[issue45356] Calling `help` executes @classmethod @property decorated methods
Randolf Scholz
report at bugs.python.org
Sun Oct 10 06:37:36 EDT 2021
Randolf Scholz <randolf.scholz at gmail.com> added the comment:
If fact, in the current state it seem that it is impossible to implement real class-properties, for a simple reason:
descriptor.__set__ is only called when setting the attribute of an instance, but not of a class!!
```python
import math
class TrigConst:
const = math.pi
def __get__(self, obj, objtype=None):
print("__get__ called")
return self.const
def __set__(self, obj, value):
print("__set__ called")
self.const = value
class Trig:
const = TrigConst() # Descriptor instance
```
```python
Trig().const # calls TrigConst.__get__
Trig().const = math.tau # calls TrigConst.__set__
Trig.const # calls TrigConst.__get__
Trig.const = math.pi # overwrites TrigConst attribute with float.
```
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45356>
_______________________________________
More information about the Python-bugs-list
mailing list