ruff/crates/ruff_linter/resources/test/fixtures/pyflakes
plredmond da882b6657
F401 - Recommend adding unused import bindings to `__all__` (#11314)
Followup on #11168 and resolve #10391

# User facing changes

* F401 now recommends a fix to add unused import bindings to to
`__all__` if a single `__all__` list or tuple is found in `__init__.py`.
* If there are no `__all__` found in the file, fall back to recommending
redundant-aliases.
* If there are multiple `__all__` or only one but of the wrong type (non
list or tuple) then diagnostics are generated without fixes.
* `fix_title` is updated to reflect what the fix/recommendation is.

Subtlety: For a renamed import such as `import foo as bees`, we can
generate a fix to add `bees` to `__all__` but cannot generate a fix to
produce a redundant import (because that would break uses of the binding
`bees`).

# Implementation changes

* Add `name` field to `ImportBinding` to contain the name of the
_binding_ we want to add to `__all__` (important for the `import foo as
bees` case). It previously only contained the `AnyImport` which can give
us information about the import but not the binding.
* Add `binding` field to `UnusedImport` to contain the same. (Naming
note: the field `name` field already existed on `UnusedImport` and
contains the qualified name of the imported symbol/module)
* Change `fix_by_reexporting` to branch on the size of `dunder_all:
Vec<&Expr>`
* For length 0 call the edit-producing function `make_redundant_alias`.
  * For length 1 call edit-producing function `add_to_dunder_all`.
  * Otherwise, produce no fix.
* Implement the edit-producing function `add_to_dunder_all` and add unit
tests.
* Implement several fixture tests: empty `__all__ = []`, nonempty
`__all__ = ["foo"]`, mis-typed `__all__ = None`, plus-eq `__all__ +=
["foo"]`
* `UnusedImportContext::Init` variant now has two fields: whether the
fix is in `__init__.py` and how many `__all__` were found.

# Other changes

* Remove a spurious pattern match and instead use field lookups b/c the
addition of a field would have required changing the unrelated pattern.
* Tweak input type of `make_redundant_alias`

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-05-14 17:02:33 -07:00
..
F401_24 F401 - Distinguish between imports we wish to remove and those we wish to make explicit-exports (#11168) 2024-05-02 16:10:32 -07:00
F401_25__all_nonempty F401 - Recommend adding unused import bindings to `__all__` (#11314) 2024-05-14 17:02:33 -07:00
F401_26__all_empty F401 - Recommend adding unused import bindings to `__all__` (#11314) 2024-05-14 17:02:33 -07:00
F401_27__all_mistyped F401 - Recommend adding unused import bindings to `__all__` (#11314) 2024-05-14 17:02:33 -07:00
F401_28__all_multiple F401 - Recommend adding unused import bindings to `__all__` (#11314) 2024-05-14 17:02:33 -07:00
F401_29__all_conditional F401 - Recommend adding unused import bindings to `__all__` (#11314) 2024-05-14 17:02:33 -07:00
project/foo Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F50x.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_0.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_1.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_3.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_4.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_5.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_6.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_7.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_8.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_9.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_10.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_11.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_12.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_13.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_14.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_15.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_16.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_17.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_18.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F401_19.py Lazily evaluate all PEP 695 type alias values (#8033) 2023-10-17 21:50:26 -04:00
F401_20.py Iterate over lambdas in deferred type annotations (#9175) 2023-12-18 04:51:23 +00:00
F401_21.py Recursively visit deferred AST nodes (#9541) 2024-01-15 20:34:38 -05:00
F401_22.py Recursively visit deferred AST nodes (#9541) 2024-01-15 20:34:38 -05:00
F401_23.py Treat `typing.Annotated` subscripts as type definitions (#10285) 2024-03-07 19:51:54 -05:00
F402.ipynb Add cell indexes to all diagnostics (#9387) 2024-01-04 14:02:23 +00:00
F402.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F403.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F404_0.py Remove special pre-visit for module docstrings (#9261) 2023-12-23 10:03:12 -05:00
F404_1.py Remove special pre-visit for module docstrings (#9261) 2023-12-23 10:03:12 -05:00
F405.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F406.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F407.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F502.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F503.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F504.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F521.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F522.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F523.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F524.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F525.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F541.py Add support for PEP 701 (#7376) 2023-09-29 02:55:39 +00:00
F601.py Avoid invalid fix for parenthesized values in F601 (#7559) 2023-09-21 01:28:11 +00:00
F602.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F622.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F631.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F632.py Skip all bracketed expressions when locating comparison ops (#7740) 2023-10-01 14:57:40 +00:00
F633.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F634.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F701.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F702.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F704.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F706.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F707.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F722.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_0.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_1.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_3.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_4.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_5.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_6.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_7.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_8.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_9.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_10.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_11.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_12.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_13.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_14.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_15.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_16.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_17.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_18.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_19.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_20.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_21.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_22.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_23.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_24.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_25.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_26.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F811_27.py Don't flag `redefined-while-unused` in if branches (#9418) 2024-01-08 17:06:55 -05:00
F811_28.py Avoid removing shadowed imports that point to different symbols (#10387) 2024-03-13 15:44:28 +00:00
F811_29.pyi Don't treat annotations as redefinitions in `.pyi` files (#10512) 2024-03-21 12:22:50 -04:00
F821_0.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_1.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_3.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_4.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_5.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_5.pyi F821, F822: fix false positive for `.pyi` files; add more test coverage for `.pyi` files (#10341) 2024-03-11 22:15:24 +00:00
F821_6.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_7.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_8.pyi Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_9.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_10.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_11.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_11.pyi F821, F822: fix false positive for `.pyi` files; add more test coverage for `.pyi` files (#10341) 2024-03-11 22:15:24 +00:00
F821_12.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_13.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_14.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_15.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_16.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F821_17.py Add support for PEP 696 syntax (#11120) 2024-04-26 09:47:29 +02:00
F821_18.py Allow bindings to be created and referenced within annotations (#7885) 2023-10-10 03:51:00 +00:00
F821_19.py Allow bindings to be created and referenced within annotations (#7885) 2023-10-10 03:51:00 +00:00
F821_20.py Lazily evaluate all PEP 695 type alias values (#8033) 2023-10-17 21:50:26 -04:00
F821_21.py Treat display as a builtin in IPython (#8707) 2023-11-16 01:58:44 +00:00
F821_22.ipynb Treat display as a builtin in IPython (#8707) 2023-11-16 01:58:44 +00:00
F821_23.py Respect dictionary unpacking in `NamedTuple` assignments (#8810) 2023-11-21 19:30:48 +00:00
F821_24.py Fix scoping for generators in named expressions in classes (#9248) 2023-12-22 18:06:40 +00:00
F821_25.py Respect attribute chains when resolving builtin call paths (#9309) 2023-12-29 15:13:24 +00:00
F821_26.py F821, F822: fix false positive for `.pyi` files; add more test coverage for `.pyi` files (#10341) 2024-03-11 22:15:24 +00:00
F821_26.pyi [`pyflakes`] Allow forward references in class bases in stub files (`F821`) (#10779) 2024-04-07 01:15:58 +01:00
F821_27.py Fix F821 false negatives when `from __future__ import annotations` is active (attempt 2) (#10524) 2024-03-22 18:11:16 +00:00
F821_28.py Apply NFKC normalization to unicode identifiers in the lexer (#10412) 2024-03-18 11:56:56 +00:00
F821_29.py 'Revert "F821: Fix false negatives in .py files when `from __future__ import annotations` is active (#10362)"' (#10513) 2024-03-21 16:41:05 +00:00
F822_0.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F822_0.pyi F821, F822: fix false positive for `.pyi` files; add more test coverage for `.pyi` files (#10341) 2024-03-11 22:15:24 +00:00
F822_1.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F822_1b.py Improve `ruff_python_semantic::all::extract_all_names()` (#11335) 2024-05-08 17:09:31 +01:00
F822_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F822_3.py Respect `# noqa` directives on `__all__` openers (#10798) 2024-04-06 14:51:17 +00:00
F823.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F841_0.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F841_1.py Fix `F841` false negative on assignment to multiple variables (#8489) 2023-11-05 12:01:10 -05:00
F841_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F841_3.py Rename `Autofix` to `Fix` (#7657) 2023-09-28 10:53:05 +00:00
F841_4.py Fix `F841` false negative on assignment to multiple variables (#8489) 2023-11-05 12:01:10 -05:00
F842.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
F901.py Improve handling of builtin symbols in linter rules (#10919) 2024-04-16 11:37:31 +01:00
__init__.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
builtins.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
future_annotations.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
multi_statement_lines.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
typing_modules.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00