py2.1->py2.3.3 __getattr__ confusion

Peter Otten __peter__ at web.de
Mon Jul 5 05:16:27 EDT 2004


Holger Joukl wrote:

> Peter wrote:
>>That is, starting with Python 2.3 the repr() and str() functions no longer
>>mask exceptions other than AttributeError. Solution: make sure you raise

Contrary to my previous post, the culprit seems to be getattr() rather than
repr(). See

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Python/bltinmodule.c

Comment for Revision 2.241:
"SF patch #471852 (anonymous) notes that getattr(obj, name, default)
masks any exception, not just AttributeError.  Fix this."

> an
>>AttributeError instead of the current KeyError for nonexistent attributes.
> 
> Thank you! Hmm, did I overlook that in the what?s new/release notes?

I would think that code built on the assumption that arbitrary Exceptions
get masked by getattr() is buggy and above quote from cvs supports this
view. It's not a feature, it's a bug (fix).

Peter


 
 




More information about the Python-list mailing list