[Python-Dev] Values and objects

Chris Angelico rosuav at gmail.com
Sun May 11 02:08:09 EDT 2014


[ I think you meant for this to go to python-list, not python-dev.
Sending this to python-list. ]

On Sun, May 11, 2014 at 3:27 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Seriously though, error messages are chosen to provide a simple and clear
> description that will help the user track down what went wrong, not for
> enshrining in exact detail the language semantics.  Would you really rather
> have:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 2, in func
> UnboundLocalError: the name 'not_here' does not yet exist as you have not
> yet assigned anything to it so there is currently no variable by that name
> although at some point (in the future of this function, or perhaps in a
> branch that has been passed and did not execute) you will or did assign
> something to it so it will exist in the future of this function or may exist
> at this point in a future run of this function.
>
> or:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 2, in func
> UnboundLocalError: local variable 'not_here' referenced before assignment

The way I'd say it is: The error text should be brief, and can leave
stuff out, but should not actively *conflict* with language semantics.
So if it says there's a local variable that hasn't been assigned, I
would expect it to mean that there is, according to language
semantics, a local variable that can be in a state of
not-being-assigned to. If that's not the case, the message definitely
needs to be changed, because it's actively misleading.

ChrisA



More information about the Python-list mailing list