Randolf Scholz <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue45356>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com