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@python components: Documentation messages: 302033 nosy: Benjamin Wohlwend, docs@python priority: normal severity: normal status: open title: Descriptor example in documentation is confusing, possibly wrong _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue31441> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com