Skip to content

Commit

Permalink
Restore redefined-while-unused violations in classes (#5926)
Browse files Browse the repository at this point in the history
## Summary

This is a regression from a recent refactor whereby we moved these
checks to a deferred pass.

Closes #5918.
  • Loading branch information
charliermarsh authored Jul 20, 2023
1 parent b866cbb commit c948dcc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions crates/ruff/resources/test/fixtures/pyflakes/F811_26.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Class:
def func(self):
pass

def func(self):
pass
10 changes: 5 additions & 5 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4935,11 +4935,6 @@ impl<'a> Checker<'a> {
}
}

// Imports in classes are public members.
if scope.kind.is_class() {
continue;
}

// F402
if self.enabled(Rule::ImportShadowedByLoopVar) {
for (name, binding_id) in scope.bindings() {
Expand Down Expand Up @@ -5072,6 +5067,11 @@ impl<'a> Checker<'a> {
}
}

// Imports in classes are public members.
if scope.kind.is_class() {
continue;
}

if enforce_typing_imports {
let runtime_imports: Vec<&Binding> = if self.settings.flake8_type_checking.strict {
vec![]
Expand Down
1 change: 1 addition & 0 deletions crates/ruff/src/rules/pyflakes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ mod tests {
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_23.py"))]
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_24.py"))]
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_25.py"))]
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_26.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"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/ruff/src/rules/pyflakes/mod.rs
---
F811_26.py:5:9: F811 Redefinition of unused `func` from line 2
|
3 | pass
4 |
5 | def func(self):
| ^^^^ F811
6 | pass
|


0 comments on commit c948dcc

Please sign in to comment.