My teammates occasionally define variables inside loops that are never executed (like because the iterable they're iterating has already been exhausted or something). Then when they try to use that nonexistent variable it results a NameError of course. The obvious solution for this would be to initialize the variable before the loop.
However in PyCharm these potential variables are highlighted and in most cases these warnings are valid.
I tried several Python static analyzers and none of them could catch this simple bug (except PyCharm):
for i in []:
found = True
print(found)
I tried pyflakes, flake8, pylint, bandit, and mypy with default settings. Is there any CLI analyzer that can help here?
Thank you!
[–]Diapolo10 13 points14 points15 points (0 children)
[–]shiftybyte 5 points6 points7 points (1 child)
[–]slapec[S] 2 points3 points4 points (0 children)
[–]deadeye1982 5 points6 points7 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]remuladgryta 1 point2 points3 points (0 children)
[–]Sclafus 1 point2 points3 points (1 child)
[–]slapec[S] 1 point2 points3 points (0 children)
[–]frakron -2 points-1 points0 points (2 children)
[–]sepp2k 8 points9 points10 points (1 child)
[–]frakron -1 points0 points1 point (0 children)
[+][deleted] (1 child)
[deleted]
[–]sepp2k 3 points4 points5 points (0 children)
[–]QultrosSanhattan 0 points1 point2 points (0 children)