Message403582
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.
``` |
|
Date |
User |
Action |
Args |
2021-10-10 10:37:36 | randolf.scholz | set | recipients:
+ randolf.scholz, terry.reedy, wim.glenn, corona10, AlexWaygood |
2021-10-10 10:37:36 | randolf.scholz | set | messageid: <1633862256.9.0.00436901792346.issue45356@roundup.psfhosted.org> |
2021-10-10 10:37:36 | randolf.scholz | link | issue45356 messages |
2021-10-10 10:37:36 | randolf.scholz | create | |
|