This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients BreamoreBoy, ncoghlan, the.mulhern
Date 2015-03-10.12:07:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1425989274.41.0.584161822622.issue20659@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2015-03-10 12:07:54ncoghlansetrecipients: + ncoghlan, BreamoreBoy, the.mulhern
2015-03-10 12:07:54ncoghlansetmessageid: <1425989274.41.0.584161822622.issue20659@psf.upfronthosting.co.za>
2015-03-10 12:07:54ncoghlanlinkissue20659 messages
2015-03-10 12:07:54ncoghlancreate