summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-04-11 22:21:22 (GMT)
committerGitHub <noreply@github.com>2021-04-11 22:21:22 (GMT)
commit553ee2781a37ac9d2068da3e1325a780ca79e21e (patch)
tree599710562c5961edb6d7365761da242a8c122680 /Objects
parent53114ffef1d4facf9aa5545e711abbbda66f672a (diff)
downloadcpython-553ee2781a37ac9d2068da3e1325a780ca79e21e.zip
cpython-553ee2781a37ac9d2068da3e1325a780ca79e21e.tar.gz
cpython-553ee2781a37ac9d2068da3e1325a780ca79e21e.tar.bz2
bpo-43682: Make staticmethod objects callable (GH-25117)
Static methods (@staticmethod) are now callable as regular functions.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/funcobject.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index df59131..f0b0b67 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -1040,6 +1040,13 @@ sm_init(PyObject *self, PyObject *args, PyObject *kwds)
return 0;
}
+static PyObject*
+sm_call(PyObject *callable, PyObject *args, PyObject *kwargs)
+{
+ staticmethod *sm = (staticmethod *)callable;
+ return PyObject_Call(sm->sm_callable, args, kwargs);
+}
+
static PyMemberDef sm_memberlist[] = {
{"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
{"__wrapped__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
@@ -1107,7 +1114,7 @@ PyTypeObject PyStaticMethod_Type = {
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
- 0, /* tp_call */
+ sm_call, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */