[Python-3000] Confused about getattr() and special methods

Thomas Wouters thomas at python.org
Tue Sep 4 12:00:16 CEST 2007


On 9/4/07, Thomas Heller <theller at ctypes.org> wrote:

> Shouldn't the __getattr__ implementation find the __iter__ method
> of the _stream instance variable?


No. For new-style classes, the special methods (that are part of the PyType
C struct) are always looked up on the class, never the instance. The class's
__getattr__ is never called. It's the class that defines behaviour, and
__getattr__ and __getattribute__ just define how to handle *instance*
attribute access.

This change is really the biggest difference between classic classes and
new-style classes, much bigger than the MRO change ;-)

-- 
Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070904/df911e34/attachment.htm 


More information about the Python-3000 mailing list