More informative error messages (Re: [Python-Dev] Efficient
predicates for the standard library)
ianb at colorstudy.com
Tue Oct 7 20:41:48 EDT 2003
On Tuesday, October 7, 2003, at 10:44 AM, Phillip J. Eby wrote:
> At 01:33 PM 10/7/03 +1300, Greg Ewing wrote:
>> While we're on the subject of error messages, I'd like to
>> point out another one that could be improved. Often one
>> sees things like
>> TypeError: foo() takes exactly 1 argument (2 given)
>> In the case where foo() is a method of some class, and there
>> are various versions of foo() defined in various superclasses,
>> it's sometimes hard to tell exactly *which* foo it was trying
>> to call. It would be much more useful if the module and
>> class names were included in the error message, e.g.
>> TypeError: MyStuff.SomeClass.foo() takes exactly 1 argument (2
> AFAICT, this would at least require a compiler change, and a change to
> the layout of code objects, so that a code object would know its
> "dotted name".
Methods know their class, and classes know their name, so it should be
okay. In the case of functions, they know their module.
>> The same goes for function names quoted in the traceback.
> Don't tracebacks give line number and file?
Yeah, that seems unnecessary. In the other case (incorrect arguments)
it can be hard because you only get the line number of the caller, not
the function being called.
There's other situations, like list.index, which says "list.index(x): x
not in list", when it is almost always useful to know what "x" is. I
can't think of other ones off the top of my head, but I know there's
many more. Is it helpful (or annoying) to open bugs on these?
Personally, I usually add the repr of any interesting arguments to my
exceptions. But many of Python's exceptions don't do this. Is there a
reasoning there? Sometimes the repr of an object can be verbose, or in
getting it you can cause a second error. Is this the reason for the
lack of information, or is it just an oversight? Or a differing
opinion on how one should debug things?
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
More information about the Python-Dev