[Python-Dev] About 'superobject' and descriptors (original) (raw)
Steven D'Aprano steve at pearwood.info
Thu Oct 24 01:48:51 CEST 2013
- Previous message: [Python-Dev] About 'superobject' and descriptors
- Next message: [Python-Dev] Updated PEP 454 (tracemalloc): no more metrics!
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Hakril,
I think this question is probably off-topic for this list. This list is for development of the Python compiler, not for development with Python, and questions like this should probably go to python-list at python.org (also mirrored as comp.lang.python if you have Usenet access). But I have a brief observation below:
On Wed, Oct 23, 2013 at 07:29:03PM +0200, hakril lse wrote:
For example:
# A.descr is a descriptor # B inherit from A # C inherit from B c = C() c.descr super(C, c).descr super(B, c).descr In these 3 cases the get method is called with the same arguments that are : get(descr, c, C). If this behavior is really expected: Could you explain why ? because it means that I am missing something obvious. Because, at first sight, the 'type' argument seems to be the perfect place to get the type of the 'real calling class'.
I'm afraid I don't understand what you mean by "real calling class", if it is not the class of the instance doing the calling.
I have a feeling that perhaps you think that calls to super are equivalent to "the parent of the class", and so you expect:
c.desc => desc.get(c, C) super(C, c).desc => desc.get(c, B) super(B, c).desc => desc.get(c, A)
but that would not be correct. super is equivalent to "the next class in the MRO of the instance doing the calling", and in all cases, the "real-calling instance" is c, and the "real calling class" is the class of c, namely C.
Extended discussion of this should go to python-list, but I think I have the basics right.
-- Steven
- Previous message: [Python-Dev] About 'superobject' and descriptors
- Next message: [Python-Dev] Updated PEP 454 (tracemalloc): no more metrics!
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]