-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
F401 - update documentation and deprecate
ignore_init_module_imports
(
#11436) ## Summary * Update documentation for F401 following recent PRs * #11168 * #11314 * Deprecate `ignore_init_module_imports` * Add a deprecation pragma to the option and a "warn user once" message when the option is used. * Restore the old behavior for stable (non-preview) mode: * When `ignore_init_module_imports` is set to `true` (default) there are no `__init_.py` fixes (but we get nice fix titles!). * When `ignore_init_module_imports` is set to `false` there are unsafe `__init__.py` fixes to remove unused imports. * When preview mode is enabled, it overrides `ignore_init_module_imports`. * Fixed a bug in fix titles where `import foo as bar` would recommend reexporting `bar as bar`. It now says to reexport `foo as foo`. (In this case we don't issue a fix, fwiw; it was just a fix title bug.) ## Test plan Added new fixture tests that reuse the existing fixtures for `__init__.py` files. Each of the three situations listed above has fixture tests. The F401 "stable" tests cover: > * When `ignore_init_module_imports` is set to `true` (default) there are no `__init_.py` fixes (but we get nice fix titles!). The F401 "deprecated option" tests cover: > * When `ignore_init_module_imports` is set to `false` there are unsafe `__init__.py` fixes to remove unused imports. These complement existing "preview" tests that show the new behavior which recommends fixes in `__init__.py` according to whether the import is 1st party and other circumstances (for more on that behavior see: #11314).
- Loading branch information
Showing
19 changed files
with
491 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
47 changes: 47 additions & 0 deletions
47
...ots/ruff_linter__rules__pyflakes__tests__F401_deprecated_option_F401_24____init__.py.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
__init__.py:19:8: F401 [*] `sys` imported but unused; consider removing, adding to `__all__`, or using a redundant alias | ||
| | ||
19 | import sys # F401: remove unused | ||
| ^^^ F401 | ||
| | ||
= help: Remove unused import: `sys` | ||
|
||
ℹ Unsafe fix | ||
16 16 | import argparse as argparse # Ok: is redundant alias | ||
17 17 | | ||
18 18 | | ||
19 |-import sys # F401: remove unused | ||
20 19 | | ||
21 20 | | ||
22 21 | # first-party | ||
|
||
__init__.py:33:15: F401 [*] `.unused` imported but unused; consider removing, adding to `__all__`, or using a redundant alias | ||
| | ||
33 | from . import unused # F401: change to redundant alias | ||
| ^^^^^^ F401 | ||
| | ||
= help: Remove unused import: `.unused` | ||
|
||
ℹ Unsafe fix | ||
30 30 | from . import aliased as aliased # Ok: is redundant alias | ||
31 31 | | ||
32 32 | | ||
33 |-from . import unused # F401: change to redundant alias | ||
34 33 | | ||
35 34 | | ||
36 35 | from . import renamed as bees # F401: no fix | ||
|
||
__init__.py:36:26: F401 [*] `.renamed` imported but unused; consider removing, adding to `__all__`, or using a redundant alias | ||
| | ||
36 | from . import renamed as bees # F401: no fix | ||
| ^^^^ F401 | ||
| | ||
= help: Remove unused import: `.renamed` | ||
|
||
ℹ Unsafe fix | ||
33 33 | from . import unused # F401: change to redundant alias | ||
34 34 | | ||
35 35 | | ||
36 |-from . import renamed as bees # F401: no fix |
50 changes: 50 additions & 0 deletions
50
...r__rules__pyflakes__tests__F401_deprecated_option_F401_25__all_nonempty____init__.py.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
__init__.py:19:8: F401 [*] `sys` imported but unused; consider removing, adding to `__all__`, or using a redundant alias | ||
| | ||
19 | import sys # F401: remove unused | ||
| ^^^ F401 | ||
| | ||
= help: Remove unused import: `sys` | ||
|
||
ℹ Unsafe fix | ||
16 16 | import argparse # Ok: is exported in __all__ | ||
17 17 | | ||
18 18 | | ||
19 |-import sys # F401: remove unused | ||
20 19 | | ||
21 20 | | ||
22 21 | # first-party | ||
|
||
__init__.py:36:15: F401 [*] `.unused` imported but unused; consider removing, adding to `__all__`, or using a redundant alias | ||
| | ||
36 | from . import unused # F401: add to __all__ | ||
| ^^^^^^ F401 | ||
| | ||
= help: Remove unused import: `.unused` | ||
|
||
ℹ Unsafe fix | ||
33 33 | from . import exported # Ok: is exported in __all__ | ||
34 34 | | ||
35 35 | | ||
36 |-from . import unused # F401: add to __all__ | ||
37 36 | | ||
38 37 | | ||
39 38 | from . import renamed as bees # F401: add to __all__ | ||
|
||
__init__.py:39:26: F401 [*] `.renamed` imported but unused; consider removing, adding to `__all__`, or using a redundant alias | ||
| | ||
39 | from . import renamed as bees # F401: add to __all__ | ||
| ^^^^ F401 | ||
| | ||
= help: Remove unused import: `.renamed` | ||
|
||
ℹ Unsafe fix | ||
36 36 | from . import unused # F401: add to __all__ | ||
37 37 | | ||
38 38 | | ||
39 |-from . import renamed as bees # F401: add to __all__ | ||
40 39 | | ||
41 40 | | ||
42 41 | __all__ = ["argparse", "exported"] |
Oops, something went wrong.