refactor: standardize on absolute imports repo-wide#823
Merged
Conversation
Convert all intra-package relative imports to absolute and enforce the convention so it cannot regress. Motivation: ruff's import combining works on the literal module-path string, so a relative and an absolute import of the same module (e.g. `from .containers import Interval` next to `from lean_spec.spec.forks.lstar.containers import ...`) were never merged. The package mixed both styles, which defeated auto-combining and produced duplicate import blocks. Absolute imports are the more standardized choice: PEP 8 recommends them, Google's style guide bans relative imports outright, and the CPython standard library uses absolute throughout. Changes: - Enable flake8-tidy-imports `ban-relative-imports = "all"` and add `TID` to ruff's select/fixable lists, so relative imports are now a lint error. - Convert ~660 relative imports across 132 files to absolute via ruff's TID252 autofix, then re-sort with isort. - Fix two namespace-package roots the autofix mis-resolved (`tests/` has no `__init__.py` chain): `helpers.*` and `gossipsub.*` now use their full `tests.lean_spec.*` paths. `just check` passes (ruff, ruff format, ty, codespell, mdformat). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Convert all intra-package relative imports to absolute and enforce the convention with ruff so it cannot regress.
Why
ruff's import combining works on the literal module-path string, so a relative and an absolute import of the same module were never merged:
The package mixed both styles (~50/50), which defeated auto-combining and left duplicate import blocks scattered around.
Absolute is the more standardized choice:
Changes
flake8-tidy-importsban-relative-imports = "all"and addTIDto ruffselect/fixable. Relative imports are now a lint error.TID252autofix, then re-sorted with isort.tests/tree uses PEP 420 namespace packages (no__init__.pychain). Correctedhelpers.*→tests.lean_spec.helpers.*andgossipsub.*→tests.lean_spec.node.networking.gossipsub.*, matching the full pathtests/api/conftest.pyalready uses.Verification
just checkpasses: ruff lint, ruff format,ty, codespell, mdformat.tyresolves every import path (would flag any broken one), and a sweep confirmed all remaining absolute roots map to real importable packages.pytestsuite was not run locally (slow); CI will exercise it.🤖 Generated with Claude Code