pytype
pytype copied to clipboard
A function reading a global variable and a loop causes an error.
When the following code is processed,
x = 1
def test():
print(x)
i = 0
while i < 3:
i += 1
the following error occurs.
pytype-single --imports_info /d/test_pytype/.pytype/imports/test_loop.imports --module-name test_loop -V 3.7 -o /d/test_pytype/.pytype/pyi/test_loop.pyi --analyze-annotated --nofail --quick /d/test_pytype/test_loop.py
ERROR:pytype.analyze:No visible options for i
File "/d/test_pytype/test_loop.py", line 3, in test: Name 'x' is not defined [name-error]
I facing many similar errors in the real world code base I currently working on.
O_o That's a weird one. I'll dig into a bit more when I have time.
Ok, I figured out what's happening. pytype is looking at i = 0; while i < 3 and deciding that the while loop can't terminate, so it thinks that definitions from import time are unreachable.
The easiest way I can think of to fix this is to discard the concrete value of i when doing the comparison.