diff --git a/crates/ruff/resources/test/fixtures/pyflakes/F821_13.py b/crates/ruff/resources/test/fixtures/pyflakes/F821_13.py new file mode 100644 index 0000000000..6646515623 --- /dev/null +++ b/crates/ruff/resources/test/fixtures/pyflakes/F821_13.py @@ -0,0 +1,8 @@ +"""Test case: ForwardRef.""" + +from typing import ForwardRef, TypeVar + +X = ForwardRef("List[int]") +Y: ForwardRef("List[int]") + +Z = TypeVar("X", "List[int]", "int") diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index 9b3ca623df..574525f502 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -3421,9 +3421,7 @@ where keywords, } => { let callable = self.ctx.resolve_call_path(func).and_then(|call_path| { - if self.ctx.match_typing_call_path(&call_path, "ForwardRef") { - Some(Callable::ForwardRef) - } else if self.ctx.match_typing_call_path(&call_path, "cast") { + if self.ctx.match_typing_call_path(&call_path, "cast") { Some(Callable::Cast) } else if self.ctx.match_typing_call_path(&call_path, "NewType") { Some(Callable::NewType) @@ -3450,12 +3448,6 @@ where } }); match callable { - Some(Callable::ForwardRef) => { - self.visit_expr(func); - for expr in args { - visit_type_definition!(self, expr); - } - } Some(Callable::Cast) => { self.visit_expr(func); if !args.is_empty() { diff --git a/crates/ruff/src/rules/pyflakes/mod.rs b/crates/ruff/src/rules/pyflakes/mod.rs index b6fab7ddf1..d591866d7c 100644 --- a/crates/ruff/src/rules/pyflakes/mod.rs +++ b/crates/ruff/src/rules/pyflakes/mod.rs @@ -107,6 +107,7 @@ mod tests { #[test_case(Rule::UndefinedName, Path::new("F821_10.py"); "F821_10")] #[test_case(Rule::UndefinedName, Path::new("F821_11.py"); "F821_11")] #[test_case(Rule::UndefinedName, Path::new("F821_12.py"); "F821_12")] + #[test_case(Rule::UndefinedName, Path::new("F821_13.py"); "F821_13")] #[test_case(Rule::UndefinedExport, Path::new("F822_0.py"); "F822_0")] #[test_case(Rule::UndefinedExport, Path::new("F822_1.py"); "F822_1")] #[test_case(Rule::UndefinedExport, Path::new("F822_2.py"); "F822_2")] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_13.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_13.py.snap new file mode 100644 index 0000000000..e00249d624 --- /dev/null +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_13.py.snap @@ -0,0 +1,18 @@ +--- +source: crates/ruff/src/rules/pyflakes/mod.rs +expression: diagnostics +--- +- kind: + name: UndefinedName + body: "Undefined name `List`" + suggestion: ~ + fixable: false + location: + row: 8 + column: 18 + end_location: + row: 8 + column: 22 + fix: ~ + parent: ~ + diff --git a/crates/ruff_python_ast/src/typing.rs b/crates/ruff_python_ast/src/typing.rs index 7d33fee52e..ee01f7b4bb 100644 --- a/crates/ruff_python_ast/src/typing.rs +++ b/crates/ruff_python_ast/src/typing.rs @@ -11,7 +11,6 @@ use crate::str; use crate::types::Range; pub enum Callable { - ForwardRef, Cast, NewType, TypeVar,