Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Regression test for https://github.com/astral-sh/ruff/issues/10874
# Explicit re-exports at module scope should not be flagged as redefined
# by class-scoped attributes with the same name.
from x import y as y

class Foo:
y = 42 # OK — class attribute, different scope from module-level re-export
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 @@ -132,6 +132,7 @@ mod tests {
#[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_32.py"))]
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_33.pyi"))]
#[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
Expand Up @@ -126,6 +126,13 @@ pub(crate) fn redefined_while_unused(checker: &Checker, scope_id: ScopeId, scope
) {
continue;
}

// Don't flag explicit re-exports (e.g., `from x import y as y`).
// A binding in a nested scope (like a class attribute) doesn't
// invalidate a module-level re-export.
if shadowed.is_explicit_export() {
continue;
}
}

// If the bindings are in different forks, abort.
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
---