ruff/crates/ruff_linter/resources/test/fixtures/pyflakes
Dhruv Manilawala 899a52390b
Evaluate default parameter value in enclosing scope (#12852)
## Summary

This PR fixes a bug in the semantic model where it would evaluate the
default parameter value in the type parameter scope. For example,

```py
def foo[T1: int](a = T1):
    pass
```

Here, the `T1` in `a = T1` is undefined but Ruff doesn't flag it
(https://play.ruff.rs/ba2f7c2f-4da6-417e-aa2a-104aa63e6d5e).

The fix here is to evaluate the default parameter value in the
_enclosing_ scope instead.

## Test Plan

Add a test case which includes the above code under `F821`
(`undefined-name`) and validate the snapshot.
2024-08-13 19:25:49 +05:30
..
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
F401_30.py Fix NFKC normalization bug when removing unused imports (#12571) 2024-07-30 09:54:35 +00: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 Use `Tokens` from parsed type annotation or parsed source (#11740) 2024-06-05 07:50:33 +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
F811_30.py [`pyflakes`] Detect assignments that shadow definitions (`F811`) (#11961) 2024-06-23 13:29:32 -04:00
F811_31.py Consider `with` blocks as single-item branches (#12311) 2024-07-13 15:22:17 -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 Evaluate default parameter value in enclosing scope (#12852) 2024-08-13 19:25:49 +05:30
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