[New-bugs-announce] [issue44973] @classmethod can be stacked on @property, but @staticmethod cannot
Tushar Sadhwani
report at bugs.python.org
Sun Aug 22 02:39:43 EDT 2021
New submission from Tushar Sadhwani <tushar.sadhwani000 at gmail.com>:
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.
----------
messages: 400051
nosy: tusharsadhwani
priority: normal
severity: normal
status: open
title: @classmethod can be stacked on @property, but @staticmethod cannot
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44973>
_______________________________________
More information about the New-bugs-announce
mailing list