New submission from Tushar Sadhwani <tushar.sadhwani...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue44973>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to