Having read this question I can understand why this warning might be output, but I have a specific case when the loop variable can not be undefined...
for i in range(0, 2):
print i
print i
PyLinting the above I get
W: 4,6: Using possibly undefined loop variable 'i'
Is PyLint
not clever enough to note that the built in range()
function will always produce a populated list in this case and so i
will always be set for the last print
statement? I can understand if it was a under-defined function, because PyLint could not possibly know what the function does... but in this case it is a well known function and surely this usage would be common?
If so, is it better to supress the warning or define i
before the loop (which seems wasteful)?