I want to annotate a type of a variable in a for
-loop.
I tried this:
for i: int in range(5):
pass
But it didn\'t work, obv
According to PEP 526, this is not allowed:
In addition, one cannot annotate variables used in a
for
orwith
statement; they can be annotated ahead of time, in a similar manner to tuple unpacking
Annotate it before the loop:
i: int
for i in range(5):
pass
PyCharm 2018.1 and up now recognizes the type of the variable inside the loop. This was not supported in older PyCharm versions.