Compare commits

...

1 Commits

Author SHA1 Message Date
Micha Reiser
ace116342c Fix F811 false positive when a class field has the same name as an unused import 2024-10-26 11:05:27 +02:00
4 changed files with 22 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
"""Regression test for: https://github.com/astral-sh/ruff/issues/13930"""
from queue import Empty
class Types:
INVALID = 0
UINT = 1
HEX = 2
Empty = 3

View File

@@ -261,6 +261,14 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
) {
continue;
}
// If the re-definition is a class member, abort.
// from bar import foo
// class Test:
// bar = 10 # Okay
if scope.kind.is_class() {
continue;
}
}
// If the bindings are in different forks, abort.

View File

@@ -129,6 +129,7 @@ mod tests {
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_29.pyi"))]
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_30.py"))]
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_31.py"))]
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_class_fields.py"))]
#[test_case(Rule::UndefinedName, Path::new("F821_0.py"))]
#[test_case(Rule::UndefinedName, Path::new("F821_1.py"))]
#[test_case(Rule::UndefinedName, Path::new("F821_2.py"))]

View File

@@ -0,0 +1,4 @@
---
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
---