One of my junior colleague wrote the following code
File: a.py
s = None
for i in range(10):
s.startswith('hello')
s = ""
Line 3 for sure throws none reference error but he didn't notice.
I'm shocked that PyCharm does not warn this, and flake8 and pylint on our continuous integration do not report this error either.
$ flake8 a.py
a.py:3:1: W191 indentation contains tabs
a.py:4:1: W191 indentation contains tabs
$ pylint a.py
************* Module a
a.py:3:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
a.py:4:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
a.py:1:0: C0114: Missing module docstring (missing-module-docstring)
a.py:1:0: C0103: Constant name "s" doesn't conform to UPPER_CASE naming style (invalid-name)
a.py:4:1: C0103: Constant name "s" doesn't conform to UPPER_CASE naming style (invalid-name)
--------------------------------------------------------------------
Your code has been rated at -2.50/10 (previous run: -2.50/10, +0.00)
Besides educating the junior to test code more carefully, is there any linter or static analysis tool that is able to report this none reference error in a loop?