This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients alex, benjamin.peterson, georg.brandl, jhylton, r.david.murray
Date 2010-10-26.11:59:59
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1288094407.14.0.650582015449.issue10189@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2010-10-26 12:00:07r.david.murraysetrecipients: + r.david.murray, jhylton, georg.brandl, benjamin.peterson, alex
2010-10-26 12:00:07r.david.murraysetmessageid: <1288094407.14.0.650582015449.issue10189@psf.upfronthosting.co.za>
2010-10-26 12:00:00r.david.murraylinkissue10189 messages
2010-10-26 12:00:00r.david.murraycreate