Message302033
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. |
|
Date |
User |
Action |
Args |
2017-09-13 08:38:27 | Benjamin Wohlwend | set | recipients:
+ Benjamin Wohlwend, docs@python |
2017-09-13 08:38:27 | Benjamin Wohlwend | set | messageid: <1505291907.9.0.809761592922.issue31441@psf.upfronthosting.co.za> |
2017-09-13 08:38:27 | Benjamin Wohlwend | link | issue31441 messages |
2017-09-13 08:38:27 | Benjamin Wohlwend | create | |
|