PyWart: NameError trackbacks are superfluous

Oscar Benjamin oscar.j.benjamin at
Sat Mar 16 22:19:34 CET 2013

On 16 March 2013 18:27, Rick Johnson <rantingrickjohnson at> wrote:
> Sometimes many levels of trace messages can be helpful when detecting bugs, however, in the case of NameErrors,  these "nuggets" ejected from deep within the bowls of the Python interpreter are nothing more than steaming piles of incomprehensible crap!
> We don't need multiple layers of traces for NameErrors. Python does not have *real* global variables; and thank Guido for that! All we need to know is which module the error occurred in AND which line of that module contains the offensive lookup of a name that does not exist.

NameErrors can occur conditionally depending on e.g. the arguments to
a function. Consider the following script:

  def broken(x):
      if x > 2:


When run it gives a NameError with a traceback:

$ python
Traceback (most recent call last):
  File "", line 8, in <module>
  File "", line 6, in broken
NameError: global name 'undefined_name' is not defined

The traceback shows the arguments passed to the broken function that
caused the NameError to be generated. Different arguments would not
have generated the NameError. This information can be useful if the
logic of the function in question is complicated. It also hints at why
you were calling the function and what your code is trying to do.


More information about the Python-list mailing list