Detect possible UnboundLocalError in the editor

Dec 10, 2013 at 2:15 PM
Given following Python code i typed in VS 2012
def f():
   a = None
   if a is None:
       l = []
       for t in l:
           print t
           q = [5]
       if 5 in q:
           print q
       else:
           print "nok"
   else:
      print "a is not None"

a = f()
If i run this, it will give a UnboundLocalError

Traceback (most recent call last):
File "t.py", line 16, in <module>
a = f()
File "t.py", line 9, in f
if 5 in q:
UnboundLocalError: local variable 'q' referenced before assignment

But can the editor not dectect that q is possibly referenced after the assignment that is never reached? I have rather more false positives than getting no feedback at all
Coordinator
Dec 10, 2013 at 6:35 PM
The editor does not currently try to detect errors like this, and focuses mainly on type information for code completion. Adding the ability to detect problems like that, , e.g. by integrating with PyLint, has been a popular feature request, and so it is definitely on our radar.