More informative error messages (Re: [Python-Dev] Efficient
predicates for the standard library)
Guido van Rossum
guido at python.org
Wed Oct 8 00:14:04 EDT 2003
> > What should the error message be in this case?
> >
> > class C:
> > pass
> >
> > def f(self, a): pass
> >
> > C.f = f
>
> I wouldn't mind if it reported f as a top-level function
> in that case.
My point was that the runtime can't distinguish this case from
class C:
def f(self, a): pass
so the error message has to be the same in both cases.
If we want the error message in the latter example to be different,
we'll have to provide extra information in the code object.
If we don't want to do that, we *may* still be able to recover the
fact that we were calling a bound method, but in that case the former
example will give the same error message as the latter.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list