[Python-Dev] Traceback style

Ka-Ping Yee ping@lfw.org
Tue, 2 May 2000 02:47:34 -0700 (PDT)


This was also going to go out after i posted the
display/displaytb patch.  But anyway, let's see what
you all think.

I propose the following stylistic changes to traceback
printing:

    1.  If there is no function name for a given level
        in the traceback, just omit the ", in ?" at the
        end of the line.

    2.  If a given level of the traceback is in a method,
        instead of just printing the method name, print
        the class and the method name.

    3.  Instead of beginning each line with:
        
            File "foo.py", line 5

        print the line first and drop the quotes:

            Line 5 of foo.py

        In the common interactive case that the file
        is a typed-in string, the current printout is
        
            File "<stdin>", line 1
        
        and the following is easier to read in my opinion:

            Line 1 of <stdin>

Here is an example:

    >>> class Spam:
    ...     def eggs(self):
    ...         return self.ham
    ... 
    >>> s = Spam()
    >>> s.eggs()
    Traceback (innermost last):
      File "<stdin>", line 1, in ?
      File "<stdin>", line 3, in eggs
    AttributeError: ham

With the suggested changes, this would print as

    Traceback (innermost last):
      Line 1 of <stdin>
      Line 3 of <stdin>, in Spam.eggs
    AttributeError: ham



-- ?!ng

"In the sciences, we are now uniquely privileged to sit side by side
with the giants on whose shoulders we stand."
    -- Gerald Holton