Skip to content

Commit

Permalink
[pyflakes] Treat arguments passed to the default= parameter of `T…
Browse files Browse the repository at this point in the history
…ypeVar` as type expressions (`F821`) (#15679)
  • Loading branch information
AlexWaygood authored Jan 22, 2025
1 parent 05abd64 commit 555b3a6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from typing import TypeVar

# Forward references are okay for both `bound` and `default` in a stub file
_P = TypeVar("_P", bound=X, default=X)

class X: ...
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ impl<'a> Visitor<'a> for Checker<'a> {
range: _,
} = keyword;
if let Some(id) = arg {
if id.as_str() == "bound" {
if matches!(&**id, "bound" | "default") {
self.visit_type_definition(value);
} else {
self.visit_non_type_definition(value);
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rules/pyflakes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ mod tests {
#[test_case(Rule::UndefinedName, Path::new("F821_28.py"))]
#[test_case(Rule::UndefinedName, Path::new("F821_30.py"))]
#[test_case(Rule::UndefinedName, Path::new("F821_31.py"))]
#[test_case(Rule::UndefinedName, Path::new("F821_32.pyi"))]
#[test_case(Rule::UndefinedExport, Path::new("F822_0.py"))]
#[test_case(Rule::UndefinedExport, Path::new("F822_0.pyi"))]
#[test_case(Rule::UndefinedExport, Path::new("F822_1.py"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
---

0 comments on commit 555b3a6

Please sign in to comment.