[Python-3000] __special__ method lookup [was Re: Confused about getattr() and special methods]
Nick Coghlan
ncoghlan at gmail.com
Tue Sep 4 12:27:49 CEST 2007
Georg Brandl wrote:
> Thomas Heller schrieb:
>
>> IIUC, in py3k, classic classes do not exist any longer, so the __metaclass__ line
>> has no effect anyway. Is this behaviour intended?
>
> It is another incarnation of special methods being looked up on the class,
> not the instance. This was always the behavior with new-style classes, see
> the thread at
>
> http://mail.python.org/pipermail/python-3000/2007-March/006261.html
>
> for a previous discussion.
>
> I think we should tackle this issue now and make sure the decided resolution
> is consistently applied throughout Python.
This issue came up when implementing PEP 343 as well - because the with
statement is just syntactic sugar without any dedicated opcodes,
__enter__/__exit__ are accessed via a conventional attribute lookup
opcode. So unlike the special methods that use a C-level slot in the
type object, these two operations *can* be affected by instance
attributes and __getattr__.
However, Guido did say at the time that he was OK with the effect of
instance attributes on special method lookups being formally undefined
and implementation dependent. I wasn't too worried either way - mucking
with special methods outside the scope of 'provide this on your class to
support operation X' has long been a pretty dubious exercise.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list