python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.43k stars 2.82k forks source link

Using annotated global/nonlocal variables is allowed #2789

Open afrieder opened 7 years ago

afrieder commented 7 years ago
x: int = 5

if True:
    global x
    x += 1

passes mypy, but raises a syntax error when run: SyntaxError: annotated name 'x' can't be global

Similar things happen with nonlocal in the proper context.

JukkaL commented 7 years ago

This looks like a mypy bug. Thanks for reporting this!

gvanrossum commented 7 years ago

Indeed, the syntax error is specified PEP 526.