respect annotation-only declarations in infer_place_load
This commit is contained in:
@@ -31,17 +31,17 @@ def f():
|
||||
reveal_type(x) # revealed: Unknown | Literal[1]
|
||||
```
|
||||
|
||||
## Skips annotation-only assignment
|
||||
## Reads respect annotation-only declarations
|
||||
|
||||
```py
|
||||
def f():
|
||||
x = 1
|
||||
x: int = 1
|
||||
def g():
|
||||
# it's pretty weird to have an annotated assignment in a function where the
|
||||
# name is otherwise not defined; maybe should be an error?
|
||||
x: int
|
||||
# TODO: This example should actually be an unbound variable error. However to avoid false
|
||||
# positives, we'd need to analyze `nonlocal x` statements in other inner functions.
|
||||
x: str
|
||||
def h():
|
||||
reveal_type(x) # revealed: Unknown | Literal[1]
|
||||
reveal_type(x) # revealed: str
|
||||
```
|
||||
|
||||
## The `nonlocal` keyword
|
||||
@@ -229,7 +229,7 @@ def f():
|
||||
nonlocal x # error: [invalid-syntax] "no binding for nonlocal `x` found"
|
||||
```
|
||||
|
||||
## `nonlocal` bindings respect declared types from the defining scope, even without a binding
|
||||
## Assigning to a `nonlocal` respects the declared type from its defining scope, even without a binding in that scope
|
||||
|
||||
```py
|
||||
def f():
|
||||
|
||||
Reference in New Issue
Block a user