[Python-ideas] staticmethod and classmethod should be callable

Serhiy Storchaka storchaka at gmail.com
Wed Jun 20 13:27:17 EDT 2018

20.06.18 20:07, Guido van Rossum пише:
> Maybe we're misunderstanding each other? I would think that calling the 
> classmethod object directly would just call the underlying function, so 
> this should have to call utility() with a single arg. This is really the 
> only option, since the descriptor doesn't have any context.
> In any case it should probably `def utility(cls)` in that example to 
> clarify that the first arg to a class method is a class.

Sorry, I missed the cls parameter in the definition of utility().

class Spam:
     def utility(cls, arg):

     value = utility(???, arg)

What should be passed as the first argument to utility() if the Spam 
class (as well as its subclasses) is not defined still?

Maybe there is a use case for calling the staticmethod descriptor. 
Although in this rare case I would apply the staticmethod decorator 
after using the function in the class body.

class Spam:
     # @staticmethod
     def utility(arg):

     value = utility(arg)
     utility = staticmethod(utility)

But I don't see a use case for calling the classmethod descriptor.

More information about the Python-ideas mailing list