[Python-ideas] staticmethod and classmethod should be callable
INADA Naoki
songofacandy at gmail.com
Thu Jun 21 05:00:14 EDT 2018
>
>
> My question is really: assuming that we redesign
> staticmethod/classmethod anyway, should we make them callable?
>
I think so. staticmethod and classmethod should affect descriptor
behavior.
And it should behave as normal function.
>>> @classmethod
... def foo(cls):
... print(cls)
...
>>> @staticmethod
... def bar(arg):
... print(arg)
...
>>> foo(int) # this should work
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'classmethod' object is not callable
>>> bar(42) # this should work too
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'staticmethod' object is not callable
When Python 4, I think we can even throw away classmethod and staticmethod
object.
PyFunction can have binding flag instead, like METH_CLASS and METH_STATIC
for PyCFunction.
classmethod and staticmethod is just a function which modify the flag.
But I'm not sure. Calling in Python is too complicated to fully
understand.
Regards,
--
INADA Naoki <songofacandy at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180621/a4e83208/attachment.html>
More information about the Python-ideas
mailing list