Message400051
Starting with Python3.9, `@classmethod` can be stacked on top of `@property`, but it seems that `@staticmethod` cannot.
>>> class C:
... @classmethod
... @property
... def cm(cls):
... return cls.__name__
... @staticmethod
... @property
... def magic_number():
... return 42
...
>>> C.cm
'C'
>>> C.magic_number
<property object at 0x7f0ad3c1ea90>
>>>
This feels like inconsistent behaviour, plus, having staticmethod properties can be useful for creating read-only class attributes, for eg:
class C:
@staticmethod
@property
def FINE_STRUCTURE_CONSTANT():
return 1 / 137
This would make it hard to accidentally modify the constant inside the class. |
|
Date |
User |
Action |
Args |
2021-08-22 06:39:43 | tusharsadhwani | set | recipients:
+ tusharsadhwani |
2021-08-22 06:39:43 | tusharsadhwani | set | messageid: <1629614383.81.0.292978789456.issue44973@roundup.psfhosted.org> |
2021-08-22 06:39:43 | tusharsadhwani | link | issue44973 messages |
2021-08-22 06:39:43 | tusharsadhwani | create | |
|