[Python-ideas] Re: staticmethod with property

2021-08-25 Thread Antoine Rozo
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
 a écrit :
>
> 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
> >>> 
>
> a = Foo()
> a.bar
> >>> 
> ```
>
> Is there any particular reason for this? Any don't we make it work?
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/M45PDOVAKJPFI55JUM3QREW3OYMW7NF5/
> Code of Conduct: http://python.org/psf/codeofconduct/



-- 
Antoine Rozo
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3RMJ6YS4KOTT5OZGBKA5D5JWEEVCNOAH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: staticmethod with property

2021-08-25 Thread Steven D'Aprano
On Tue, Aug 24, 2021 at 11:55:21PM -, 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
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VFUPUP5OIGDL56X5BPQZ57QR6AFFQ2QK/
Code of Conduct: http://python.org/psf/codeofconduct/