-
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.
[pyflakes] Avoid false positives in
@no_type_check
contexts (F821, …
…F722) (#14615)
- Loading branch information
Showing
9 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
crates/ruff_linter/resources/test/fixtures/pyflakes/F722_1.py
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,21 @@ | ||
"""Regression test for #13824. | ||
Don't report an error when the function being annotated has the | ||
`@no_type_check` decorator. | ||
However, we still want to ignore this annotation on classes. See | ||
https://github.com/python/typing/pull/1615/files and the discussion on #14615. | ||
""" | ||
|
||
from typing import no_type_check | ||
|
||
|
||
@no_type_check | ||
def f(arg: "this isn't python") -> "this isn't python either": | ||
x: "this also isn't python" = 0 | ||
|
||
|
||
@no_type_check | ||
class C: | ||
def f(arg: "this isn't python") -> "this isn't python either": | ||
x: "this also isn't python" = 1 |
21 changes: 21 additions & 0 deletions
21
crates/ruff_linter/resources/test/fixtures/pyflakes/F821_30.py
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,21 @@ | ||
"""Regression test for #13824. | ||
Don't report an error when the function being annotated has the | ||
`@no_type_check` decorator. | ||
However, we still want to ignore this annotation on classes. See | ||
https://github.com/python/typing/pull/1615/files and the discussion on #14615. | ||
""" | ||
|
||
import typing | ||
|
||
|
||
@typing.no_type_check | ||
def f(arg: "A") -> "R": | ||
x: "A" = 1 | ||
|
||
|
||
@typing.no_type_check | ||
class C: | ||
def f(self, arg: "B") -> "S": | ||
x: "B" = 1 |
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
29 changes: 29 additions & 0 deletions
29
...ter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F722_F722_1.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,29 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
snapshot_kind: text | ||
--- | ||
F722_1.py:20:16: F722 Syntax error in forward annotation: `this isn't python` | ||
| | ||
18 | @no_type_check | ||
19 | class C: | ||
20 | def f(arg: "this isn't python") -> "this isn't python either": | ||
| ^^^^^^^^^^^^^^^^^^^ F722 | ||
21 | x: "this also isn't python" = 1 | ||
| | ||
|
||
F722_1.py:20:40: F722 Syntax error in forward annotation: `this isn't python either` | ||
| | ||
18 | @no_type_check | ||
19 | class C: | ||
20 | def f(arg: "this isn't python") -> "this isn't python either": | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ F722 | ||
21 | x: "this also isn't python" = 1 | ||
| | ||
|
||
F722_1.py:21:12: F722 Syntax error in forward annotation: `this also isn't python` | ||
| | ||
19 | class C: | ||
20 | def f(arg: "this isn't python") -> "this isn't python either": | ||
21 | x: "this also isn't python" = 1 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ F722 | ||
| |
29 changes: 29 additions & 0 deletions
29
...er/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F821_F821_30.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,29 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
snapshot_kind: text | ||
--- | ||
F821_30.py:20:23: F821 Undefined name `B` | ||
| | ||
18 | @typing.no_type_check | ||
19 | class C: | ||
20 | def f(self, arg: "B") -> "S": | ||
| ^ F821 | ||
21 | x: "B" = 1 | ||
| | ||
|
||
F821_30.py:20:31: F821 Undefined name `S` | ||
| | ||
18 | @typing.no_type_check | ||
19 | class C: | ||
20 | def f(self, arg: "B") -> "S": | ||
| ^ F821 | ||
21 | x: "B" = 1 | ||
| | ||
|
||
F821_30.py:21:13: F821 Undefined name `B` | ||
| | ||
19 | class C: | ||
20 | def f(self, arg: "B") -> "S": | ||
21 | x: "B" = 1 | ||
| ^ F821 | ||
| |
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