Nick Coghlan added the comment:

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)

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20659>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to