[Patches] Patch: AttributeError and NameError: second attempt.
Nick Mathewson
nickm@MIT.EDU
Tue, 30 May 2000 14:00:29 -0400
Guido van Rossum <guido@python.org> wrote:
>[Nick Mathewson wrote:]
>> When you throw an AttributeError on an Object now, you
>> need to generate a new string containing the Object's type and the
>> missing attribute. With my patch, even _this_ work was postponed until
>> you printed the exception.
>>
>> Nick
>
>Good point. The less work is done when the exception is raised, the
>better. (I think that since the traceback is available separately it
>shouldn't be necessary to reference the frame or the namespace from
>the exception.)
I agree on the frame and the namespace. I can patch NameError
traceback printing to give these better error via tracebacks, either
directly or on-the-fly through an 'import warnings' mechanism. BTW,
in addition to case, my latest patch also catches users who forget
that 'self.' should precede instance attributes; this is one of the
most common errors in comp.lang.python.
I have still have a problem, however.
My original patch handled AttributeError as well as NameError. As
near as I can tell, there is no way to use tracebacks to find the
objects associated with AttributeErrors. This means that in code like
import string
string.JOIN(....)
I have no way to tell that the 'JOIN' attribute was supposed to be
invoked on a string object. In my original patch, I stored the
'string' object as an attribute of the exception, but if I can't do
that, I don't think I can do anything meaningful with AttributeError.
How should I proceed?
A-warning-mechanism-would-certainly-be-nice-ly y'rs,
--
Nick