[New-bugs-announce] [issue17032] Misleading error message: global name 'X' is not defined
report at bugs.python.org
Fri Jan 25 15:42:54 CET 2013
New submission from Ram Rachum:
Every single time I see the error message `global name 'X' is not defined` I say to myself, "ah yeah, I mistyped a variable name."
But then it occurred to me, why should I have to do this mental translation from "global name not defined" to "I mistyped a variable name"?
Now, I'm not asking for the error message to say "You mistyped a variable name", because that goes too much into second-guessing the user. But can we at least drop the reference to a global name? I understand that Python first searches the local namespace, and only then in the global namespace, and if the name isn't found there then an error is raised. But that doesn't mean that the error message should just assume that the variable is supposed to be global. It's misleading to say that a variable is global when it's in fact local.
I think that the error message should just say `Variable 'X' not defined`. Maybe add a suggestion `(Typo?)` at the end.
>>> def f():
... meow = 0
... return meoow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in f
NameError: global name 'meoow' is not defined
I'd make the error message:
NameError: Variable 'meoow' is not defined
components: Interpreter Core
title: Misleading error message: global name 'X' is not defined
versions: Python 3.4, Python 3.5
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce