[New-bugs-announce] [issue31441] Descriptor example in documentation is confusing, possibly wrong

Benjamin Wohlwend report at bugs.python.org
Wed Sep 13 04:38:27 EDT 2017


New submission from Benjamin Wohlwend:

The first descriptor example in the descriptor docs (https://docs.python.org/3/howto/descriptor.html#descriptor-example) stores the value on the descriptor instance, which is shared among all MyClass instances. This leads to surprising (and arguably buggy from a user perspective) behaviour:

    m1, m2 = MyClass(), MyClass()
    m1.x = 5
    m2.x = 10
    print(m1.x, m2.x)
    >>> 10 10

I'm not sure how this could be fixed without making the example much more complicated (e.g. by introducing a "values" weakref dictionary on the descriptor instance). 

Maybe pointing this behaviour out in the docs could be enough, although I don't see any useful use case for a class that has this behaviour.

----------
assignee: docs at python
components: Documentation
messages: 302033
nosy: Benjamin Wohlwend, docs at python
priority: normal
severity: normal
status: open
title: Descriptor example in documentation is confusing, possibly wrong

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31441>
_______________________________________


More information about the New-bugs-announce mailing list