This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author PiDelport
Recipients PiDelport
Date 2008-04-10.10:15:06
SpamBayes Score 0.091007136
Marked as misclassified No
Message-id <1207822509.14.0.860100540347.issue2605@psf.upfronthosting.co.za>
In-reply-to
Content
Short version:  __get__/__set__/__delete__ attributes on descriptor objects
(as opposed to their types) are treated inconsistently as part of the
descriptor
protocol:  the documentation and support code includes them;  the core
implementation doesn't.

Example:

    class D(object):
        __get__ = lambda self, i, o: 'D'

    class C(object):
        d = D()
        d.__get__ = lambda i, o: 'd'
        d.__set__ = lambda i, v: 1/0

    c = C()

According to pydoc and inspect, and the description in the reference manual
(section 3.4.2.3), d's __get__ and __set__ override D's:

    >>> inspect.isdatadescriptor(C.__dict__['d'])
    True
    >>> help(C)
    class C(__builtin__.object)
    |  Data descriptors defined here:
    ...
    |  d

    >>> type(c).__dict__['d'].__get__(c, type(c))
    'd'
    >>> type(c).__dict__['d'].__set__(c, 5)
    ZeroDivisionError: integer division or modulo by zero

According to CPython, they have no effect:

    >>> c.d
    'D'
    >>> c.d = 5; c.d
    5

PEP 252 notes: "For speed, the get and set methods are type slots", which
points to the CPython behavior being an intentional concession for
performance.

Should CPython respect descriptor object attributes, if reasonable
performance
can be maintained?  Otherwise, should the documentation and support code be
changed to ignore them?
History
Date User Action Args
2008-04-10 10:15:09PiDelportsetspambayes_score: 0.0910071 -> 0.091007136
recipients: + PiDelport
2008-04-10 10:15:09PiDelportsetspambayes_score: 0.0910071 -> 0.0910071
messageid: <1207822509.14.0.860100540347.issue2605@psf.upfronthosting.co.za>
2008-04-10 10:15:08PiDelportlinkissue2605 messages
2008-04-10 10:15:06PiDelportcreate