This project has moved and is read-only. For the latest updates, please go here.

Detect possible UnboundLocalError in the editor

Dec 10, 2013 at 3: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
           print "nok"
      print "a is not None"

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

Traceback (most recent call last):
File "", line 16, in <module>
a = f()
File "", 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
Dec 10, 2013 at 7: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.