staticmethod with property

Currently Python does not support using `@staticmethod` decorator along with `@property` decorator. I think that the it currently works is a bit misleading since it will not give an error, but gives the following outcome. ``` class Foo: @staticmethod @property def bar(): return "1" ``` ``` class Foo: @property @staticmethod def bar(): return "1" ``` In wither of the cases the outcome is the following ``` Foo.bar
<property at 0x112dbaf40>
a = Foo() a.bar
<property at 0x112dbaf40>
Is there any particular reason for this? Any don't we make it work?

On Tue, Aug 24, 2021 at 11:55:21PM -0000, Henry Harutyunyan wrote:
Currently Python does not support using `@staticmethod` decorator along with `@property` decorator.
What is the purpose of using both staticmethod and property? Is it just to avoid type "self" in the parameter list?
I think that the it currently works is a bit misleading since it will not give an error, but gives the following outcome.
I'm not sure that staticmethod is supposed to be used with arbitrary objects such as property objects, and vice versa. I believe that they are intended to work on function objects. Nevertheless, I think that the behaviour is technically correct, if rather unexpected and probably not helpful. If you can explain why you want to chain property and staticmethod, and the required behaviour, perhaps we could make an enhancement to them. -- Steve

Properties couldn't work with static methods as they need to access the instance or its type. And properties are not class-properties by design, because you may want to access directly to the fields of the property object. But you can define your own descriptor type to make a kind of class-property (read-only). Le mer. 25 août 2021 à 01:56, Henry Harutyunyan <henryharutyunyan@gmail.com> a écrit :
-- Antoine Rozo

On Tue, Aug 24, 2021 at 11:55:21PM -0000, Henry Harutyunyan wrote:
Currently Python does not support using `@staticmethod` decorator along with `@property` decorator.
What is the purpose of using both staticmethod and property? Is it just to avoid type "self" in the parameter list?
I think that the it currently works is a bit misleading since it will not give an error, but gives the following outcome.
I'm not sure that staticmethod is supposed to be used with arbitrary objects such as property objects, and vice versa. I believe that they are intended to work on function objects. Nevertheless, I think that the behaviour is technically correct, if rather unexpected and probably not helpful. If you can explain why you want to chain property and staticmethod, and the required behaviour, perhaps we could make an enhancement to them. -- Steve

Properties couldn't work with static methods as they need to access the instance or its type. And properties are not class-properties by design, because you may want to access directly to the fields of the property object. But you can define your own descriptor type to make a kind of class-property (read-only). Le mer. 25 août 2021 à 01:56, Henry Harutyunyan <henryharutyunyan@gmail.com> a écrit :
-- Antoine Rozo
participants (3)
-
Antoine Rozo
-
Henry Harutyunyan
-
Steven D'Aprano