Visitar URL original
[`pyflakes`] `F401` autofix should only add a first-party import to `__all__` if the import is from the same package by 11happy · Pull Request #23035 · astral-sh/ruff · GitHub
Skip to content

[pyflakes] F401 autofix should only add a first-party import to __all__ if the import is from the same package - #23035

Open
11happy wants to merge 8 commits into
astral-sh:mainfrom
11happy:F401_fix
Open

11happy wants to merge 8 commits into
astral-sh:mainfrom
11happy:F401_fix

Conversation

@11happy

@11happy 11happy commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes #13008

Test Plan

This changes a lot of snapshots 20+, currently have not included , making it a draft PR

@astral-sh-bot

astral-sh-bot Bot commented Feb 2, 2026 •

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+22 -22 violations, +0 -0 fixes in 4 projects; 52 projects unchanged)

PostHog/HouseWatch (+2 -2 violations, +0 -0 fixes)

+ housewatch/models/__init__.py:2:21: F401 `.backup.ScheduledBackup` imported but unused
- housewatch/models/__init__.py:2:21: F401 `.backup.ScheduledBackup` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ housewatch/models/__init__.py:2:38: F401 `.backup.ScheduledBackupRun` imported but unused
- housewatch/models/__init__.py:2:38: F401 `.backup.ScheduledBackupRun` imported but unused; consider removing, adding to `__all__`, or using a redundant alias

binary-husky/gpt_academic (+4 -4 violations, +0 -0 fixes)

+ crazy_functions/paper_fns/file2file_doc/__init__.py:1:22: F401 `.txt_doc.TxtFormatter` imported but unused
- crazy_functions/paper_fns/file2file_doc/__init__.py:1:22: F401 `.txt_doc.TxtFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ crazy_functions/paper_fns/file2file_doc/__init__.py:2:27: F401 `.markdown_doc.MarkdownFormatter` imported but unused
- crazy_functions/paper_fns/file2file_doc/__init__.py:2:27: F401 `.markdown_doc.MarkdownFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ crazy_functions/paper_fns/file2file_doc/__init__.py:3:23: F401 `.html_doc.HtmlFormatter` imported but unused
- crazy_functions/paper_fns/file2file_doc/__init__.py:3:23: F401 `.html_doc.HtmlFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ crazy_functions/paper_fns/file2file_doc/__init__.py:4:23: F401 `.word_doc.WordFormatter` imported but unused
- crazy_functions/paper_fns/file2file_doc/__init__.py:4:23: F401 `.word_doc.WordFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias

latchbio/latch (+2 -2 violations, +0 -0 fixes)

+ src/latch_cli/services/init/example_conda/__init__.py:10:35: F401 `latch.resources.tasks.small_task` imported but unused
- src/latch_cli/services/init/example_conda/__init__.py:10:35: F401 `latch.resources.tasks.small_task` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ src/latch_cli/services/init/example_r/__init__.py:10:35: F401 `latch.resources.tasks.small_task` imported but unused
- src/latch_cli/services/init/example_r/__init__.py:10:35: F401 `latch.resources.tasks.small_task` imported but unused; consider removing, adding to `__all__`, or using a redundant alias

qdrant/qdrant-client (+14 -14 violations, +0 -0 fixes)

+ qdrant_client/migrate/__init__.py:1:22: F401 `.migrate.migrate` imported but unused
- qdrant_client/migrate/__init__.py:1:22: F401 `.migrate.migrate` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:1:31: F401 `.call_transformer.CallTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:1:31: F401 `.call_transformer.CallTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:2:36: F401 `.class_def_transformer.ClassDefTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:2:36: F401 `.class_def_transformer.ClassDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:3:35: F401 `.constant_transformer.ConstantTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:3:35: F401 `.constant_transformer.ConstantTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:4:39: F401 `.function_def_transformer.FunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:4:39: F401 `.function_def_transformer.FunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:5:38: F401 `.import_from_transformer.ImportFromTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:5:38: F401 `.import_from_transformer.ImportFromTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:6:33: F401 `.import_transformer.ImportTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:6:33: F401 `.import_transformer.ImportTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:7:31: F401 `.name_transformer.NameTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:7:31: F401 `.name_transformer.NameTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/client/__init__.py:1:39: F401 `.function_def_transformer.ClientFunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/client/__init__.py:1:39: F401 `.function_def_transformer.ClientFunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/fastembed/__init__.py:1:31: F401 `.call_transformer.FastembedCallTransformer` imported but unused
- tools/async_client_generator/transformers/fastembed/__init__.py:1:31: F401 `.call_transformer.FastembedCallTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/fastembed/__init__.py:2:39: F401 `.function_def_transformer.FastembedFunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/fastembed/__init__.py:2:39: F401 `.function_def_transformer.FastembedFunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/local/__init__.py:1:31: F401 `.call_transformer.LocalCallTransformer` imported but unused
- tools/async_client_generator/transformers/local/__init__.py:1:31: F401 `.call_transformer.LocalCallTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/remote/__init__.py:1:39: F401 `.function_def_transformer.RemoteFunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/remote/__init__.py:1:39: F401 `.function_def_transformer.RemoteFunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/remote/__init__.py:2:38: F401 `.import_from_transformer.RemoteImportFromTransformer` imported but unused
- tools/async_client_generator/transformers/remote/__init__.py:2:38: F401 `.import_from_transformer.RemoteImportFromTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
F401 44 22 22 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+22 -22 violations, +0 -0 fixes in 4 projects; 52 projects unchanged)

PostHog/HouseWatch (+2 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- housewatch/models/__init__.py:2:21: F401 [*] `.backup.ScheduledBackup` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ housewatch/models/__init__.py:2:21: F401 `.backup.ScheduledBackup` imported but unused
- housewatch/models/__init__.py:2:38: F401 [*] `.backup.ScheduledBackupRun` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ housewatch/models/__init__.py:2:38: F401 `.backup.ScheduledBackupRun` imported but unused

binary-husky/gpt_academic (+4 -4 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- crazy_functions/paper_fns/file2file_doc/__init__.py:1:22: F401 [*] `.txt_doc.TxtFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ crazy_functions/paper_fns/file2file_doc/__init__.py:1:22: F401 `.txt_doc.TxtFormatter` imported but unused
- crazy_functions/paper_fns/file2file_doc/__init__.py:2:27: F401 [*] `.markdown_doc.MarkdownFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ crazy_functions/paper_fns/file2file_doc/__init__.py:2:27: F401 `.markdown_doc.MarkdownFormatter` imported but unused
- crazy_functions/paper_fns/file2file_doc/__init__.py:3:23: F401 [*] `.html_doc.HtmlFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ crazy_functions/paper_fns/file2file_doc/__init__.py:3:23: F401 `.html_doc.HtmlFormatter` imported but unused
- crazy_functions/paper_fns/file2file_doc/__init__.py:4:23: F401 [*] `.word_doc.WordFormatter` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ crazy_functions/paper_fns/file2file_doc/__init__.py:4:23: F401 `.word_doc.WordFormatter` imported but unused

latchbio/latch (+2 -2 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- src/latch_cli/services/init/example_conda/__init__.py:10:35: F401 [*] `latch.resources.tasks.small_task` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ src/latch_cli/services/init/example_conda/__init__.py:10:35: F401 `latch.resources.tasks.small_task` imported but unused
- src/latch_cli/services/init/example_r/__init__.py:10:35: F401 [*] `latch.resources.tasks.small_task` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ src/latch_cli/services/init/example_r/__init__.py:10:35: F401 `latch.resources.tasks.small_task` imported but unused

qdrant/qdrant-client (+14 -14 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- qdrant_client/migrate/__init__.py:1:22: F401 [*] `.migrate.migrate` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ qdrant_client/migrate/__init__.py:1:22: F401 `.migrate.migrate` imported but unused
- tools/async_client_generator/transformers/__init__.py:1:31: F401 [*] `.call_transformer.CallTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:1:31: F401 `.call_transformer.CallTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:2:36: F401 [*] `.class_def_transformer.ClassDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:2:36: F401 `.class_def_transformer.ClassDefTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:3:35: F401 [*] `.constant_transformer.ConstantTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:3:35: F401 `.constant_transformer.ConstantTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:4:39: F401 [*] `.function_def_transformer.FunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:4:39: F401 `.function_def_transformer.FunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:5:38: F401 [*] `.import_from_transformer.ImportFromTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:5:38: F401 `.import_from_transformer.ImportFromTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:6:33: F401 [*] `.import_transformer.ImportTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:6:33: F401 `.import_transformer.ImportTransformer` imported but unused
- tools/async_client_generator/transformers/__init__.py:7:31: F401 [*] `.name_transformer.NameTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/__init__.py:7:31: F401 `.name_transformer.NameTransformer` imported but unused
- tools/async_client_generator/transformers/client/__init__.py:1:39: F401 [*] `.function_def_transformer.ClientFunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/client/__init__.py:1:39: F401 `.function_def_transformer.ClientFunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/fastembed/__init__.py:1:31: F401 [*] `.call_transformer.FastembedCallTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/fastembed/__init__.py:1:31: F401 `.call_transformer.FastembedCallTransformer` imported but unused
- tools/async_client_generator/transformers/fastembed/__init__.py:2:39: F401 [*] `.function_def_transformer.FastembedFunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/fastembed/__init__.py:2:39: F401 `.function_def_transformer.FastembedFunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/local/__init__.py:1:31: F401 [*] `.call_transformer.LocalCallTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/local/__init__.py:1:31: F401 `.call_transformer.LocalCallTransformer` imported but unused
- tools/async_client_generator/transformers/remote/__init__.py:1:39: F401 [*] `.function_def_transformer.RemoteFunctionDefTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/remote/__init__.py:1:39: F401 `.function_def_transformer.RemoteFunctionDefTransformer` imported but unused
- tools/async_client_generator/transformers/remote/__init__.py:2:38: F401 [*] `.import_from_transformer.RemoteImportFromTransformer` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
+ tools/async_client_generator/transformers/remote/__init__.py:2:38: F401 `.import_from_transformer.RemoteImportFromTransformer` imported but unused

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
F401 44 22 22 0 0

@amyreese
amyreese requested a review from dylwil3 February 4, 2026 01:13
@amyreese

amyreese commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Not sure if this overlaps with @dylwil3 work in #23038

@dylwil3

dylwil3 commented Feb 9, 2026 •

Copy link
Copy Markdown
Collaborator

Not sure if this overlaps with @dylwil3 work in #23038

I think this is complementary, but there will probably be merge conflicts for whoever is second to land 😄

This is on my list to review, thanks @11happy !

@dylwil3

dylwil3 commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Would you mind resolving the conflicts and getting CI to pass and then I'll give this a review?

@ntBre ntBre added bug An issue describing something that isn't working, or a PR that fixes a bug rule Implementing or modifying a lint rule labels Feb 12, 2026
Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
@11happy

11happy commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

current addition makes the autofix a little more stricter .

@11happy
11happy marked this pull request as ready for review February 13, 2026 12:01
Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
@11happy

11happy commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

Would you mind resolving the conflicts and getting CI to pass and then I'll give this a review?

done

@dylwil3 dylwil3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! A few comments:

  1. It's unfortunate that this test
    fn f401_preview_first_party_submodule(contents: &str, snapshot: &str) {
    doesn't really test what it was trying to test any more. Could you modify it so that we are in the "same package" situation? You could keep around one or two tests to ensure we don't regress on the issue that you fixed, but we also want to make sure we do suggest the autofix when we are in the same package.
  2. In the issue Alex says:

It makes sense for the autofix to add first-party imports to all if the import is from the same package (or a subpackage of that package)

Can you add a test for the behavior "subpackage of that package"?
3. Can you review the ecosystem changes and comment on whether you think they look correct?

Comment on lines +425 to +428
&& isort::categorize::same_package(
checker.package(),
binding.import.source_name()[0],
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this before the previous && operand. Also, can we remove the is_first_party above now that we are using same_package?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
@11happy

11happy commented Feb 19, 2026

Copy link
Copy Markdown
Contributor Author

added a new test and ecosystem changes looks as expected.

Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
@dylwil3 dylwil3 changed the title F401 autofix should only add a first-party import to __all__ if the import is from the same package [pyflakes] F401 autofix should only add a first-party import to __all__ if the import is from the same package Feb 19, 2026
@MichaReiser
MichaReiser requested a review from dylwil3 March 3, 2026 18:15
@11happy

11happy commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

ping! would appreciate a review. Also are there any more changes needed from my end.
Thank you :)

@ntBre
ntBre requested review from ntBre and removed request for dylwil3 June 3, 2026 19:30
@ntBre ntBre self-assigned this Jun 3, 2026
@ntBre

ntBre commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Sorry for the delay here! If you're still interested in working on this, would you mind fixing up the merge conflicts? Then I'll try to give this a review.

@11happy

11happy commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

sure : )

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

F401 autofix should only add a first-party import to __all__ if the import is from the *same package*

4 participants