R. David Murray <rdmur...@bitdance.com> added the comment: Yes, but in that particular case the exact line referenced is involved in the error, since it that error is that the symbol is both nonlocal and an argument, and the error points to the head of the block which is the 'def' statement.
Attached is a patch that adds the available line info, and also modifies the 'nonlocal at global level' message to include the symbol name. I think this change is a good idea because without the patch this code: >cat temp import foo >cat foo.py def f(): def g(): nonlocal a gives this: >./python temp Traceback (most recent call last): File "temp", line 1, in <module> import foo SyntaxError: no binding for nonlocal 'a' found which is even more confusing that not having any traceback at all. After the patch it will look like this: Traceback (most recent call last): File "temp", line 1, in <module> import foo File "/home/rdmurray/python/py3k/foo.py", line 2 def g(): SyntaxError: no binding for nonlocal 'a' found ---------- keywords: +patch Added file: http://bugs.python.org/file19368/nonlocal-traceback.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10189> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com