Skip to content

refactor: standardize on absolute imports repo-wide#823

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/absolute-imports
Jun 2, 2026
Merged

refactor: standardize on absolute imports repo-wide#823
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/absolute-imports

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

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:

from lean_spec.spec.forks.lstar.containers import (...)   # absolute
from .containers import Interval                          # relative -> same module, not 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:

  • PEP 8 recommends absolute imports.
  • Google's Python style guide bans relative imports outright.
  • The CPython standard library uses absolute throughout.

Changes

  • Config: enable flake8-tidy-imports ban-relative-imports = "all" and add TID to ruff select/fixable. Relative imports are now a lint error.
  • Code: ~660 relative imports across 132 files converted to absolute via ruff's TID252 autofix, then re-sorted with isort.
  • Two manual fixes: ruff mis-resolved two roots because the tests/ tree uses PEP 420 namespace packages (no __init__.py chain). Corrected helpers.*tests.lean_spec.helpers.* and gossipsub.*tests.lean_spec.node.networking.gossipsub.*, matching the full path tests/api/conftest.py already uses.

Verification

  • just check passes: ruff lint, ruff format, ty, codespell, mdformat.
  • ty resolves every import path (would flag any broken one), and a sweep confirmed all remaining absolute roots map to real importable packages.
  • Note: the full pytest suite was not run locally (slow); CI will exercise it.

🤖 Generated with Claude Code

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>
@tcoratger tcoratger merged commit 9bf2d2e into leanEthereum:main Jun 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant