mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:16 +00:00
[pyflakes
] Detect assignments that shadow definitions (F811
) (#11961)
## Summary This PR updates `F811` rule to include assignment as possible shadowed binding. This will fix issue: #11828 . ## Test Plan Add a test file, F811_30.py, which includes a redefinition after an assignment and a verified snapshot file.
This commit is contained in:
parent
c3f61a012e
commit
068b75cc8e
4 changed files with 85 additions and 2 deletions
|
@ -177,16 +177,31 @@ impl<'a> Binding<'a> {
|
|||
| BindingKind::Builtin => {
|
||||
return false;
|
||||
}
|
||||
// Assignment-assignment bindings are not considered redefinitions, as in:
|
||||
// ```python
|
||||
// x = 1
|
||||
// x = 2
|
||||
// ```
|
||||
BindingKind::Assignment | BindingKind::NamedExprAssignment => {
|
||||
if matches!(
|
||||
existing.kind,
|
||||
BindingKind::Assignment | BindingKind::NamedExprAssignment
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// Otherwise, the shadowed binding must be a class definition, function definition, or
|
||||
// import to be considered a redefinition.
|
||||
// Otherwise, the shadowed binding must be a class definition, function definition,
|
||||
// import, or assignment to be considered a redefinition.
|
||||
matches!(
|
||||
existing.kind,
|
||||
BindingKind::ClassDefinition(_)
|
||||
| BindingKind::FunctionDefinition(_)
|
||||
| BindingKind::Import(_)
|
||||
| BindingKind::FromImport(_)
|
||||
| BindingKind::Assignment
|
||||
| BindingKind::NamedExprAssignment
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue