19.12.21 19:41, Ethan Furman пише:
> On 12/19/21 5:40 AM, Serhiy Storchaka wrote:
> 
>> classmethod supersedes staticmethod. It was not clearly known when they
>> were introduced, but now we see that there is very few use cases for
>> staticmethod which cannot be replaced by classmethod (actually only one
>> specific case).
> 
> What is the one case?

Setting a Python function as a class attribute without making it a method.

    def func(*args, **kwargs): ...
    class A:
        f = staticmethod(func)
    a = A()
    a.f(1)  # calls func(1), not func(a, 1)

It is used in tests if there are C and Python implementations.
staticmethod(func) could be replaced with

    lambda self, /, *args, **kwargs: func(*args, **kwargs)

or

    property(lambda self: func)

in these cases.

_______________________________________________
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/J7GEEWCKIXWXOEQ4KD3ZFPA5W73ZAWVK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to