[docs] [issue31441] Descriptor example in documentation is confusing, possibly wrong
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
>>> 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
nosy: Benjamin Wohlwend, docs at python
title: Descriptor example in documentation is confusing, possibly wrong
Python tracker <report at bugs.python.org>
More information about the docs