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.