[New-bugs-announce] [issue2605] Descriptor instance attributes not interpreted consistently

Piet Delport report at bugs.python.org
Thu Apr 10 12:15:09 CEST 2008

New submission from Piet Delport <pjdelport at gmail.com>:

Short version:  __get__/__set__/__delete__ attributes on descriptor objects
(as opposed to their types) are treated inconsistently as part of the
protocol:  the documentation and support code includes them;  the core
implementation doesn't.


    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, d's __get__ and __set__ override D's:

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

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

According to CPython, they have no effect:

    >>> c.d
    >>> c.d = 5; c.d

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

Should CPython respect descriptor object attributes, if reasonable
can be maintained?  Otherwise, should the documentation and support code be
changed to ignore them?

components: Interpreter Core, Library (Lib)
messages: 65289
nosy: pjd
severity: normal
status: open
title: Descriptor instance attributes not interpreted consistently
type: behavior
versions: Python 2.2, Python 2.2.1, Python 2.2.2, Python 2.2.3, Python 2.3, Python 2.4, Python 2.5, Python 2.6, Python 3.0

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list