[Python-Dev] Avoid formatting an error message on attribute error

Serhiy Storchaka storchaka at gmail.com
Thu Nov 7 13:19:18 CET 2013


07.11.13 00:32, Victor Stinner написав(ла):
> I'm trying to avoid unnecessary temporary Unicode strings when
> possible (see issue #19512). While working on this, I saw that Python
> likes preparing an user friendly message to explain why getting an
> attribute failed. The problem is that in most cases, the caller
> doesn't care of the message: the exception is simply deleted. For
> example, hasattr() deletes immediatly the AttributeError.
>
> It would be nice to only format the message on demand. The
> AttributeError would keep a reference to the type. Keeping a strong
> reference to the type might change the behaviour of some applications
> in some corner cases. (Holding a reference to the object would be
> worse, and the type looks to be preferred over the type to format the
> error message.)

See also:

http://bugs.python.org/issue18156 : Add an 'attr' attribute to 
AttributeError
http://bugs.python.org/issue18162 : Add index attribute to IndexError
http://bugs.python.org/issue18163 : Add a 'key' attribute to KeyError




More information about the Python-Dev mailing list