[Python-Dev] About 'superobject' and descriptors

Nick Coghlan ncoghlan at gmail.com
Thu Oct 24 00:52:23 CEST 2013


On 24 Oct 2013 03:37, "hakril lse" <hakril at lse.epita.fr> wrote:
>
> Hi,
>
> I have a question about a choice of implementation concerning
> 'superobject' with the descriptors.
>
> When a 'superobject' looks for a given attribute, it runs through the
> mro of the object.
> If it finds a descriptor, the 'superobject' calls the __get__ method
> with 'starttype = su->obj_type' as third argument (in typeobject.c:
> super_getattro).
>
> So, the 'type' argument of __get__ does not give more information
> about the 'real calling type' in this case.
> It seems that this is just a redundant information of inst.__class__.
>
> 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'.

The third argument is just there to handle the case where the instance is
None (i.e. lookup directly on the class rather than an instance).

Cheers,
Nick.

>
> Thank you,
>
> --
> hakril
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131024/c9c80585/attachment.html>


More information about the Python-Dev mailing list