Skip to content

Commit 7bd951a

Browse files
authored
New semantic analyzer: add test case for redefined nonlocal variable (#7089)
Closes #7060.
1 parent 17b68c6 commit 7bd951a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test-data/unit/check-newsemanal.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,3 +2756,21 @@ def g() -> None:
27562756
x = f() # E: Need type annotation for 'x'
27572757
y = x
27582758
reveal_type(y) # N: Revealed type is '__main__.G[Any]'
2759+
2760+
[case testNewAnalyzerRedefinedNonlocal]
2761+
import typing
2762+
2763+
def f():
2764+
bar = [] # type: typing.List[int]
2765+
2766+
def foo():
2767+
nonlocal bar
2768+
bar = [] # type: typing.List[int]
2769+
2770+
def g() -> None:
2771+
bar = [] # type: typing.List[int]
2772+
2773+
def foo() -> None:
2774+
nonlocal bar
2775+
bar = [] # type: typing.List[int] # E: Name 'bar' already defined on line 11
2776+
[builtins fixtures/list.pyi]

0 commit comments

Comments
 (0)