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:
    @classmethod
    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.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to