By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

descriptors and old-style classes

P: n/a
Hi,

I've recently discovered that descriptors can be used with old-style
classes if they don't define a __set__ method (and this would be why
class and static methods are usable with old-style classes).
I understand why the __set__ method is not called with old-style
classes, but I don't understand why __get__ *is* called.
I thought the transformation from :
a.x
into :
type(a).__dict__['x'].__get__(a, type(a))
was done in object.__getattribute__ (or type.__getattribute__), but then
this does not explain why this also seems to work with old-style
classes.

Could someboby help me here ??

Cheers,
Adrien.

--
Adrien Di Mascio
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Adrien Di Mascio" <ad**@logilab.fr> wrote in message
news:sl****************@lacerta.logilab.fr...
Hi,

I've recently discovered that descriptors can be used with old-style
classes if they don't define a __set__ method (and this would be why
class and static methods are usable with old-style classes).
I understand why the __set__ method is not called with old-style
classes, but I don't understand why __get__ *is* called.
I thought the transformation from :
a.x
into :
type(a).__dict__['x'].__get__(a, type(a))
was done in object.__getattribute__ (or type.__getattribute__), but then
this does not explain why this also seems to work with old-style
classes.

Could someboby help me here ??
At a rough guess, the search logic is in __getattribute__, but the
actual invocation is probably in the bytecode somewhere.
__getattribute__, after all, is supposed to return the attribute
requested, not to invoke it.

So on an old style class, the standard search will find the
descriptor object just fine, then the bytecode will detect it
has a __get__ method and invoke it.

John Roth
Cheers,
Adrien.

--
Adrien Di Mascio
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.