Skip to content

Remove adjacent imports replaced by plain functions - #371

Open
x0Lazarus wants to merge 1 commit into
PyCQA:mainfrom
x0Lazarus:fix/adjacent-redefined-imports
Open

x0Lazarus wants to merge 1 commit into
PyCQA:mainfrom
x0Lazarus:fix/adjacent-redefined-imports

Conversation

@x0Lazarus

Copy link
Copy Markdown

Addresses #321 by handling an F811 import immediately followed by a plain function that replaces the same binding. For example, from autoflake import fix_code before def fix_code(): ... can now be removed with --remove-all-unused-imports or --imports=autoflake.

The new rule requires a single imported name and consecutive statements in a module or function body. It preserves decorators, defaults, annotations, type parameters, class bodies, ambiguous same-line imports, and the __builtins__/__name__ bindings that function creation can read. Existing import-selection, comment, and __init__ filters still apply. Adjacency is checked during each filtering pass, including after existing cleanup removes a redundant pass.

Validation on Python 3.12 / Windows:

  • The final regression tests reproduce 15 failing subcases on unchanged main; the complete suite passes with 190 tests and 52 subtests under both Pyflakes 3.4.0 and the supported minimum 3.0.0.
  • Existing fuzz checks pass in both modes; wheel/sdist builds and wheel-import smoke checks pass.
  • All seven pre-commit hooks pass with ty targeting Linux. Native Windows ty retains the same two diagnostics as unchanged main (worker_count and signal.SIGPIPE). Hosted and other Python-version checks have not run locally.

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