[Python-Dev] Improve error message "UnboundLocalError: local variable referenced before assignment"

Skip Montanaro skip at pobox.com
Wed Nov 7 15:16:57 CET 2012


> How about:
>
>   "UnboundLocalError: Local variable 'FONT_NAMES' (created on
>    line 11) referenced before assignment."
>
> What I don't really like is the term "created". Maybe "implicitly created
> on line 11"? Or "implied by line 11"? Or how about "Local variable
> FONT_NAMES (implied by line 11) doesn't refer to an object", to avoid the
> multiple interpretations of the term "assignment"?

It's been a long (long) while since I looked at the virtual machine
implementation, but my guess is that at the point where the error is
detected the system won't know what line number corresponds to the
assignment.  There might also be multiple assignments.  How would you
know which one to pick?

As for a better word than "created", I would use "assigned."

Skip


More information about the Python-Dev mailing list