More informative error messages (Re: [Python-Dev] Efficient predicates for the standard library)

Guido van Rossum guido at python.org
Tue Oct 7 22:49:07 EDT 2003


> > >   TypeError: MyStuff.SomeClass.foo() takes exactly 1 argument (2
> > >given)
> > 
> > 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".
> 
> Perhaps. I had the idea that methods already had some notion of
> the name of the class they were defined in, but maybe that's
> only bound methods. In any case, I think it would be worth
> making this change.

Only bound methods.  What should the error message be in this case?

  class C:
    pass

  def f(self, a): pass

  C.f = f

  C().f()

> > Don't tracebacks give line number and file?
> 
> Yes, but the exception occurs just *before* the function is entered,
> so the traceback stops one level short of showing you where the
> function being called is defined! That's what makes this problem
> so annoying.

Yes, that's one of the issues of this.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list