473,320 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

descriptors and old-style classes

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
1 1345

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Denis S. Otkidach | last post by:
I've noticed that the order of attribute lookup is inconsistent when descriptor is used. property instance takes precedence of instance attributes: >>> class A(object): .... def...
2
by: François Pinard | last post by:
This question is a bit technical, but hopefully, this list will offer me good hints or nice solutions. Happily enough for me, it often does! :-) I would need to recognise and play with...
14
by: Antoon Pardon | last post by:
Can anyone explain why descriptors only work when they are an attribute to an object or class. I think a lot of interesting things one can do with descriptors would be just as interesting if the...
8
by: David S. | last post by:
I am looking for a way to implement the same simple validation on many instance attributes and I thought descriptors (http://users.rcn.com/python/download/Descriptor.htm) looked like the right...
7
by: Dario | last post by:
I have an unmanaged library that handle many TCP/IP connections. In my .NET application i want to test if there is input available on these connections. Using an existing function of the unmanaged...
12
by: bruno at modulix | last post by:
Hi I'm currently playing with some (possibly weird...) code, and I'd have a use for per-instance descriptors, ie (dummy code): class DummyDescriptor(object): def __get__(self, obj,...
0
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any...
8
by: M.Endraszka | last post by:
Hi, I am writing a simple irc-like server and came across weird behavior while debugging. Could anyone tell me why the following happens : I have a class which stores pipe descriptors as a...
7
by: mrkafk | last post by:
Hello everyone, I'm trying to do seemingly trivial thing with descriptors: have another attribute updated on dot access in object defined using descriptors. For example, let's take a simple...
2
by: DJ Dharme | last post by:
Hi all, I am writing a multi-threaded application in c++ running on solaris. I have a file which is updated by a single thread by appending data into the file and at same time the other threads...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.