mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-06 16:40:39 +00:00
distinguish references from definitions in infer_nonlocal
The initial implementation of `infer_nonlocal` landed in https://github.com/astral-sh/ruff/pull/19112 fails to report an error for this example: ```py x = 1 def f(): # This is only a usage of `x`, not a definition. It shouldn't be # enough to make the `nonlocal` statement below allowed. print(x) def g(): nonlocal x ``` Fix this by continuing to walk enclosing scopes when the place we've found isn't bound, declared, or `nonlocal`.
This commit is contained in:
parent
00e7d1ffd6
commit
a357a68fc9
3 changed files with 17 additions and 5 deletions
|
@ -320,7 +320,7 @@ impl PlaceExprWithFlags {
|
|||
self.flags.contains(PlaceFlags::IS_USED)
|
||||
}
|
||||
|
||||
/// Is the place defined in its containing scope?
|
||||
/// Is the place given a value in its containing scope?
|
||||
pub fn is_bound(&self) -> bool {
|
||||
self.flags.contains(PlaceFlags::IS_BOUND)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue