Message237754
To get the behaviour you're requesting, you need to use a custom metaclass and define the property there. The reason is that the descriptor machinery is bypassed entirely when setting or deleting an attribute on the class itself:
>>> class Example:
... @property
... def p(self):
... return 1
...
>>> Example.p
<property object at 0x7f0901d7d548>
>>> Example().p
1
>>> Example().p = 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
>>> Example.p = 2
>>> Example.p
2
>>> Example().p
2
>>> Example().p = 3
Hence, the only way to get a "class property" is to use the normal @property descriptor in a custom metaclass (i.e. the class-of-the-class) |
|
Date |
User |
Action |
Args |
2015-03-10 12:07:54 | ncoghlan | set | recipients:
+ ncoghlan, BreamoreBoy, the.mulhern |
2015-03-10 12:07:54 | ncoghlan | set | messageid: <1425989274.41.0.584161822622.issue20659@psf.upfronthosting.co.za> |
2015-03-10 12:07:54 | ncoghlan | link | issue20659 messages |
2015-03-10 12:07:54 | ncoghlan | create | |
|