[Python-ideas] staticmethod and classmethod should be callable
Guido van Rossum
guido at python.org
Wed Jun 20 13:07:54 EDT 2018
On Wed, Jun 20, 2018 at 10:03 AM Serhiy Storchaka <storchaka at gmail.com>
> 20.06.18 19:37, Guido van Rossum пише:
> > On Wed, Jun 20, 2018 at 9:31 AM Serhiy Storchaka
> > <storchaka at gmail.com
> > <mailto:storchaka at gmail.com>> wrote:
> > 20.06.18 19:20, Guido van Rossum пише:
> > > +1 -- when we introduced these we didn't see the use case so
> > clearly,
> > > but it definitely exists.
> > How would you call a classmethod descriptor in this case?
> > With an extra first argument that's a class -- it should just call the
> > wrapped function with whatever args are presented to the descriptior.
> This differs from calling a class method outside of the class definition
> body. And in the class definition body the class is not defined still.
> class Spam:
> def utility(arg):
> value = utility(???, arg)
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.
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas