2 /* Function object implementation */
7 #include "structmember.h"
10 PyFunction_New(PyObject
*code
, PyObject
*globals
)
12 PyFunctionObject
*op
= PyObject_GC_New(PyFunctionObject
,
14 static PyObject
*__name__
= 0;
19 op
->func_weakreflist
= NULL
;
23 op
->func_globals
= globals
;
24 op
->func_name
= ((PyCodeObject
*)code
)->co_name
;
25 Py_INCREF(op
->func_name
);
26 op
->func_defaults
= NULL
; /* No default arguments */
27 op
->func_kwdefaults
= NULL
; /* No keyword only defaults */
28 op
->func_closure
= NULL
;
29 consts
= ((PyCodeObject
*)code
)->co_consts
;
30 if (PyTuple_Size(consts
) >= 1) {
31 doc
= PyTuple_GetItem(consts
, 0);
32 if (!PyUnicode_Check(doc
))
40 op
->func_module
= NULL
;
41 op
->func_annotations
= NULL
;
43 /* __module__: If module name is in globals, use it.
47 __name__
= PyUnicode_InternFromString("__name__");
53 module
= PyDict_GetItem(globals
, __name__
);
56 op
->func_module
= module
;
61 _PyObject_GC_TRACK(op
);
62 return (PyObject
*)op
;
66 PyFunction_GetCode(PyObject
*op
)
68 if (!PyFunction_Check(op
)) {
69 PyErr_BadInternalCall();
72 return ((PyFunctionObject
*) op
) -> func_code
;
76 PyFunction_GetGlobals(PyObject
*op
)
78 if (!PyFunction_Check(op
)) {
79 PyErr_BadInternalCall();
82 return ((PyFunctionObject
*) op
) -> func_globals
;
86 PyFunction_GetModule(PyObject
*op
)
88 if (!PyFunction_Check(op
)) {
89 PyErr_BadInternalCall();
92 return ((PyFunctionObject
*) op
) -> func_module
;
96 PyFunction_GetDefaults(PyObject
*op
)
98 if (!PyFunction_Check(op
)) {
99 PyErr_BadInternalCall();
102 return ((PyFunctionObject
*) op
) -> func_defaults
;
106 PyFunction_SetDefaults(PyObject
*op
, PyObject
*defaults
)
108 if (!PyFunction_Check(op
)) {
109 PyErr_BadInternalCall();
112 if (defaults
== Py_None
)
114 else if (defaults
&& PyTuple_Check(defaults
)) {
118 PyErr_SetString(PyExc_SystemError
, "non-tuple default args");
121 Py_XDECREF(((PyFunctionObject
*) op
) -> func_defaults
);
122 ((PyFunctionObject
*) op
) -> func_defaults
= defaults
;
127 PyFunction_GetKwDefaults(PyObject
*op
)
129 if (!PyFunction_Check(op
)) {
130 PyErr_BadInternalCall();
133 return ((PyFunctionObject
*) op
) -> func_kwdefaults
;
137 PyFunction_SetKwDefaults(PyObject
*op
, PyObject
*defaults
)
139 if (!PyFunction_Check(op
)) {
140 PyErr_BadInternalCall();
143 if (defaults
== Py_None
)
145 else if (defaults
&& PyDict_Check(defaults
)) {
149 PyErr_SetString(PyExc_SystemError
,
150 "non-dict keyword only default args");
153 Py_XDECREF(((PyFunctionObject
*)op
) -> func_kwdefaults
);
154 ((PyFunctionObject
*) op
) -> func_kwdefaults
= defaults
;
159 PyFunction_GetClosure(PyObject
*op
)
161 if (!PyFunction_Check(op
)) {
162 PyErr_BadInternalCall();
165 return ((PyFunctionObject
*) op
) -> func_closure
;
169 PyFunction_SetClosure(PyObject
*op
, PyObject
*closure
)
171 if (!PyFunction_Check(op
)) {
172 PyErr_BadInternalCall();
175 if (closure
== Py_None
)
177 else if (PyTuple_Check(closure
)) {
181 PyErr_Format(PyExc_SystemError
,
182 "expected tuple for closure, got '%.100s'",
183 closure
->ob_type
->tp_name
);
186 Py_XDECREF(((PyFunctionObject
*) op
) -> func_closure
);
187 ((PyFunctionObject
*) op
) -> func_closure
= closure
;
192 PyFunction_GetAnnotations(PyObject
*op
)
194 if (!PyFunction_Check(op
)) {
195 PyErr_BadInternalCall();
198 return ((PyFunctionObject
*) op
) -> func_annotations
;
202 PyFunction_SetAnnotations(PyObject
*op
, PyObject
*annotations
)
204 if (!PyFunction_Check(op
)) {
205 PyErr_BadInternalCall();
208 if (annotations
== Py_None
)
210 else if (annotations
&& PyDict_Check(annotations
)) {
211 Py_INCREF(annotations
);
214 PyErr_SetString(PyExc_SystemError
,
215 "non-dict annotations");
218 Py_XDECREF(((PyFunctionObject
*)op
) -> func_annotations
);
219 ((PyFunctionObject
*) op
) -> func_annotations
= annotations
;
225 #define OFF(x) offsetof(PyFunctionObject, x)
227 static PyMemberDef func_memberlist
[] = {
228 {"__closure__", T_OBJECT
, OFF(func_closure
),
229 RESTRICTED
|READONLY
},
230 {"__doc__", T_OBJECT
, OFF(func_doc
), PY_WRITE_RESTRICTED
},
231 {"__globals__", T_OBJECT
, OFF(func_globals
),
232 RESTRICTED
|READONLY
},
233 {"__module__", T_OBJECT
, OFF(func_module
), PY_WRITE_RESTRICTED
},
234 {NULL
} /* Sentinel */
238 func_get_dict(PyFunctionObject
*op
)
240 if (op
->func_dict
== NULL
) {
241 op
->func_dict
= PyDict_New();
242 if (op
->func_dict
== NULL
)
245 Py_INCREF(op
->func_dict
);
246 return op
->func_dict
;
250 func_set_dict(PyFunctionObject
*op
, PyObject
*value
)
254 /* It is illegal to del f.func_dict */
256 PyErr_SetString(PyExc_TypeError
,
257 "function's dictionary may not be deleted");
260 /* Can only set func_dict to a dictionary */
261 if (!PyDict_Check(value
)) {
262 PyErr_SetString(PyExc_TypeError
,
263 "setting function's dictionary to a non-dict");
268 op
->func_dict
= value
;
274 func_get_code(PyFunctionObject
*op
)
276 Py_INCREF(op
->func_code
);
277 return op
->func_code
;
281 func_set_code(PyFunctionObject
*op
, PyObject
*value
)
284 Py_ssize_t nfree
, nclosure
;
286 /* Not legal to del f.func_code or to set it to anything
287 * other than a code object. */
288 if (value
== NULL
|| !PyCode_Check(value
)) {
289 PyErr_SetString(PyExc_TypeError
,
290 "__code__ must be set to a code object");
293 nfree
= PyCode_GetNumFree((PyCodeObject
*)value
);
294 nclosure
= (op
->func_closure
== NULL
? 0 :
295 PyTuple_GET_SIZE(op
->func_closure
));
296 if (nclosure
!= nfree
) {
297 PyErr_Format(PyExc_ValueError
,
298 "%U() requires a code object with %zd free vars,"
306 op
->func_code
= value
;
312 func_get_name(PyFunctionObject
*op
)
314 Py_INCREF(op
->func_name
);
315 return op
->func_name
;
319 func_set_name(PyFunctionObject
*op
, PyObject
*value
)
323 /* Not legal to del f.func_name or to set it to anything
324 * other than a string object. */
325 if (value
== NULL
|| !PyUnicode_Check(value
)) {
326 PyErr_SetString(PyExc_TypeError
,
327 "__name__ must be set to a string object");
332 op
->func_name
= value
;
338 func_get_defaults(PyFunctionObject
*op
)
340 if (op
->func_defaults
== NULL
) {
344 Py_INCREF(op
->func_defaults
);
345 return op
->func_defaults
;
349 func_set_defaults(PyFunctionObject
*op
, PyObject
*value
)
353 /* Legal to del f.func_defaults.
354 * Can only set func_defaults to NULL or a tuple. */
355 if (value
== Py_None
)
357 if (value
!= NULL
&& !PyTuple_Check(value
)) {
358 PyErr_SetString(PyExc_TypeError
,
359 "__defaults__ must be set to a tuple object");
362 tmp
= op
->func_defaults
;
364 op
->func_defaults
= value
;
370 func_get_kwdefaults(PyFunctionObject
*op
)
372 if (op
->func_kwdefaults
== NULL
) {
376 Py_INCREF(op
->func_kwdefaults
);
377 return op
->func_kwdefaults
;
381 func_set_kwdefaults(PyFunctionObject
*op
, PyObject
*value
)
385 if (value
== Py_None
)
387 /* Legal to del f.func_kwdefaults.
388 * Can only set func_kwdefaults to NULL or a dict. */
389 if (value
!= NULL
&& !PyDict_Check(value
)) {
390 PyErr_SetString(PyExc_TypeError
,
391 "__kwdefaults__ must be set to a dict object");
394 tmp
= op
->func_kwdefaults
;
396 op
->func_kwdefaults
= value
;
402 func_get_annotations(PyFunctionObject
*op
)
404 if (op
->func_annotations
== NULL
) {
405 op
->func_annotations
= PyDict_New();
406 if (op
->func_annotations
== NULL
)
409 Py_INCREF(op
->func_annotations
);
410 return op
->func_annotations
;
414 func_set_annotations(PyFunctionObject
*op
, PyObject
*value
)
418 if (value
== Py_None
)
420 /* Legal to del f.func_annotations.
421 * Can only set func_annotations to NULL (through C api)
423 if (value
!= NULL
&& !PyDict_Check(value
)) {
424 PyErr_SetString(PyExc_TypeError
,
425 "__annotations__ must be set to a dict object");
428 tmp
= op
->func_annotations
;
430 op
->func_annotations
= value
;
435 static PyGetSetDef func_getsetlist
[] = {
436 {"__code__", (getter
)func_get_code
, (setter
)func_set_code
},
437 {"__defaults__", (getter
)func_get_defaults
,
438 (setter
)func_set_defaults
},
439 {"__kwdefaults__", (getter
)func_get_kwdefaults
,
440 (setter
)func_set_kwdefaults
},
441 {"__annotations__", (getter
)func_get_annotations
,
442 (setter
)func_set_annotations
},
443 {"__dict__", (getter
)func_get_dict
, (setter
)func_set_dict
},
444 {"__name__", (getter
)func_get_name
, (setter
)func_set_name
},
445 {NULL
} /* Sentinel */
448 PyDoc_STRVAR(func_doc
,
449 "function(code, globals[, name[, argdefs[, closure]]])\n\
451 Create a function object from a code object and a dictionary.\n\
452 The optional name string overrides the name from the code object.\n\
453 The optional argdefs tuple specifies the default argument values.\n\
454 The optional closure tuple supplies the bindings for free variables.");
456 /* func_new() maintains the following invariants for closures. The
457 closure must correspond to the free variables of the code object.
459 if len(code.co_freevars) == 0:
462 len(closure) == len(code.co_freevars)
463 for every elt in closure, type(elt) == cell
467 func_new(PyTypeObject
* type
, PyObject
* args
, PyObject
* kw
)
471 PyObject
*name
= Py_None
;
472 PyObject
*defaults
= Py_None
;
473 PyObject
*closure
= Py_None
;
474 PyFunctionObject
*newfunc
;
475 Py_ssize_t nfree
, nclosure
;
476 static char *kwlist
[] = {"code", "globals", "name",
477 "argdefs", "closure", 0};
479 if (!PyArg_ParseTupleAndKeywords(args
, kw
, "O!O!|OOO:function",
482 &PyDict_Type
, &globals
,
483 &name
, &defaults
, &closure
))
485 if (name
!= Py_None
&& !PyUnicode_Check(name
)) {
486 PyErr_SetString(PyExc_TypeError
,
487 "arg 3 (name) must be None or string");
490 if (defaults
!= Py_None
&& !PyTuple_Check(defaults
)) {
491 PyErr_SetString(PyExc_TypeError
,
492 "arg 4 (defaults) must be None or tuple");
495 nfree
= PyTuple_GET_SIZE(code
->co_freevars
);
496 if (!PyTuple_Check(closure
)) {
497 if (nfree
&& closure
== Py_None
) {
498 PyErr_SetString(PyExc_TypeError
,
499 "arg 5 (closure) must be tuple");
502 else if (closure
!= Py_None
) {
503 PyErr_SetString(PyExc_TypeError
,
504 "arg 5 (closure) must be None or tuple");
509 /* check that the closure is well-formed */
510 nclosure
= closure
== Py_None
? 0 : PyTuple_GET_SIZE(closure
);
511 if (nfree
!= nclosure
)
512 return PyErr_Format(PyExc_ValueError
,
513 "%U requires closure of length %zd, not %zd",
514 code
->co_name
, nfree
, nclosure
);
517 for (i
= 0; i
< nclosure
; i
++) {
518 PyObject
*o
= PyTuple_GET_ITEM(closure
, i
);
519 if (!PyCell_Check(o
)) {
520 return PyErr_Format(PyExc_TypeError
,
521 "arg 5 (closure) expected cell, found %s",
522 o
->ob_type
->tp_name
);
527 newfunc
= (PyFunctionObject
*)PyFunction_New((PyObject
*)code
,
532 if (name
!= Py_None
) {
534 Py_DECREF(newfunc
->func_name
);
535 newfunc
->func_name
= name
;
537 if (defaults
!= Py_None
) {
539 newfunc
->func_defaults
= defaults
;
541 if (closure
!= Py_None
) {
543 newfunc
->func_closure
= closure
;
546 return (PyObject
*)newfunc
;
550 func_dealloc(PyFunctionObject
*op
)
552 _PyObject_GC_UNTRACK(op
);
553 if (op
->func_weakreflist
!= NULL
)
554 PyObject_ClearWeakRefs((PyObject
*) op
);
555 Py_DECREF(op
->func_code
);
556 Py_DECREF(op
->func_globals
);
557 Py_XDECREF(op
->func_module
);
558 Py_DECREF(op
->func_name
);
559 Py_XDECREF(op
->func_defaults
);
560 Py_XDECREF(op
->func_kwdefaults
);
561 Py_XDECREF(op
->func_doc
);
562 Py_XDECREF(op
->func_dict
);
563 Py_XDECREF(op
->func_closure
);
564 Py_XDECREF(op
->func_annotations
);
569 func_repr(PyFunctionObject
*op
)
571 return PyUnicode_FromFormat("<function %U at %p>",
576 func_traverse(PyFunctionObject
*f
, visitproc visit
, void *arg
)
578 Py_VISIT(f
->func_code
);
579 Py_VISIT(f
->func_globals
);
580 Py_VISIT(f
->func_module
);
581 Py_VISIT(f
->func_defaults
);
582 Py_VISIT(f
->func_kwdefaults
);
583 Py_VISIT(f
->func_doc
);
584 Py_VISIT(f
->func_name
);
585 Py_VISIT(f
->func_dict
);
586 Py_VISIT(f
->func_closure
);
587 Py_VISIT(f
->func_annotations
);
592 function_call(PyObject
*func
, PyObject
*arg
, PyObject
*kw
)
596 PyObject
*kwtuple
= NULL
;
600 argdefs
= PyFunction_GET_DEFAULTS(func
);
601 if (argdefs
!= NULL
&& PyTuple_Check(argdefs
)) {
602 d
= &PyTuple_GET_ITEM((PyTupleObject
*)argdefs
, 0);
603 nd
= PyTuple_GET_SIZE(argdefs
);
610 if (kw
!= NULL
&& PyDict_Check(kw
)) {
612 nk
= PyDict_Size(kw
);
613 kwtuple
= PyTuple_New(2*nk
);
616 k
= &PyTuple_GET_ITEM(kwtuple
, 0);
618 while (PyDict_Next(kw
, &pos
, &k
[i
], &k
[i
+1])) {
630 result
= PyEval_EvalCodeEx(
631 (PyCodeObject
*)PyFunction_GET_CODE(func
),
632 PyFunction_GET_GLOBALS(func
), (PyObject
*)NULL
,
633 &PyTuple_GET_ITEM(arg
, 0), PyTuple_GET_SIZE(arg
),
635 PyFunction_GET_KW_DEFAULTS(func
),
636 PyFunction_GET_CLOSURE(func
));
643 /* Bind a function to an object */
645 func_descr_get(PyObject
*func
, PyObject
*obj
, PyObject
*type
)
647 if (obj
== Py_None
|| obj
== NULL
) {
651 return PyMethod_New(func
, obj
);
654 PyTypeObject PyFunction_Type
= {
655 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
657 sizeof(PyFunctionObject
),
659 (destructor
)func_dealloc
, /* tp_dealloc */
664 (reprfunc
)func_repr
, /* tp_repr */
665 0, /* tp_as_number */
666 0, /* tp_as_sequence */
667 0, /* tp_as_mapping */
669 function_call
, /* tp_call */
671 PyObject_GenericGetAttr
, /* tp_getattro */
672 PyObject_GenericSetAttr
, /* tp_setattro */
673 0, /* tp_as_buffer */
674 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
,/* tp_flags */
675 func_doc
, /* tp_doc */
676 (traverseproc
)func_traverse
, /* tp_traverse */
678 0, /* tp_richcompare */
679 offsetof(PyFunctionObject
, func_weakreflist
), /* tp_weaklistoffset */
683 func_memberlist
, /* tp_members */
684 func_getsetlist
, /* tp_getset */
687 func_descr_get
, /* tp_descr_get */
688 0, /* tp_descr_set */
689 offsetof(PyFunctionObject
, func_dict
), /* tp_dictoffset */
692 func_new
, /* tp_new */
696 /* Class method object */
698 /* A class method receives the class as implicit first argument,
699 just like an instance method receives the instance.
700 To declare a class method, use this idiom:
703 def f(cls, arg1, arg2, ...): ...
706 It can be called either on the class (e.g. C.f()) or on an instance
707 (e.g. C().f()); the instance is ignored except for its class.
708 If a class method is called for a derived class, the derived class
709 object is passed as the implied first argument.
711 Class methods are different than C++ or Java static methods.
712 If you want those, see static methods below.
717 PyObject
*cm_callable
;
721 cm_dealloc(classmethod
*cm
)
723 _PyObject_GC_UNTRACK((PyObject
*)cm
);
724 Py_XDECREF(cm
->cm_callable
);
725 Py_TYPE(cm
)->tp_free((PyObject
*)cm
);
729 cm_traverse(classmethod
*cm
, visitproc visit
, void *arg
)
731 Py_VISIT(cm
->cm_callable
);
736 cm_clear(classmethod
*cm
)
738 Py_CLEAR(cm
->cm_callable
);
744 cm_descr_get(PyObject
*self
, PyObject
*obj
, PyObject
*type
)
746 classmethod
*cm
= (classmethod
*)self
;
748 if (cm
->cm_callable
== NULL
) {
749 PyErr_SetString(PyExc_RuntimeError
,
750 "uninitialized classmethod object");
754 type
= (PyObject
*)(Py_TYPE(obj
));
755 return PyMethod_New(cm
->cm_callable
, type
);
759 cm_init(PyObject
*self
, PyObject
*args
, PyObject
*kwds
)
761 classmethod
*cm
= (classmethod
*)self
;
764 if (!PyArg_UnpackTuple(args
, "classmethod", 1, 1, &callable
))
766 if (!_PyArg_NoKeywords("classmethod", kwds
))
769 cm
->cm_callable
= callable
;
773 static PyMemberDef cm_memberlist
[] = {
774 {"__func__", T_OBJECT
, offsetof(classmethod
, cm_callable
), READONLY
},
775 {NULL
} /* Sentinel */
778 PyDoc_STRVAR(classmethod_doc
,
779 "classmethod(function) -> method\n\
781 Convert a function to be a class method.\n\
783 A class method receives the class as implicit first argument,\n\
784 just like an instance method receives the instance.\n\
785 To declare a class method, use this idiom:\n\
788 def f(cls, arg1, arg2, ...): ...\n\
789 f = classmethod(f)\n\
791 It can be called either on the class (e.g. C.f()) or on an instance\n\
792 (e.g. C().f()). The instance is ignored except for its class.\n\
793 If a class method is called for a derived class, the derived class\n\
794 object is passed as the implied first argument.\n\
796 Class methods are different than C++ or Java static methods.\n\
797 If you want those, see the staticmethod builtin.");
799 PyTypeObject PyClassMethod_Type
= {
800 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
804 (destructor
)cm_dealloc
, /* tp_dealloc */
810 0, /* tp_as_number */
811 0, /* tp_as_sequence */
812 0, /* tp_as_mapping */
816 PyObject_GenericGetAttr
, /* tp_getattro */
818 0, /* tp_as_buffer */
819 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC
,
820 classmethod_doc
, /* tp_doc */
821 (traverseproc
)cm_traverse
, /* tp_traverse */
822 (inquiry
)cm_clear
, /* tp_clear */
823 0, /* tp_richcompare */
824 0, /* tp_weaklistoffset */
828 cm_memberlist
, /* tp_members */
832 cm_descr_get
, /* tp_descr_get */
833 0, /* tp_descr_set */
834 0, /* tp_dictoffset */
835 cm_init
, /* tp_init */
836 PyType_GenericAlloc
, /* tp_alloc */
837 PyType_GenericNew
, /* tp_new */
838 PyObject_GC_Del
, /* tp_free */
842 PyClassMethod_New(PyObject
*callable
)
844 classmethod
*cm
= (classmethod
*)
845 PyType_GenericAlloc(&PyClassMethod_Type
, 0);
848 cm
->cm_callable
= callable
;
850 return (PyObject
*)cm
;
854 /* Static method object */
856 /* A static method does not receive an implicit first argument.
857 To declare a static method, use this idiom:
860 def f(arg1, arg2, ...): ...
863 It can be called either on the class (e.g. C.f()) or on an instance
864 (e.g. C().f()); the instance is ignored except for its class.
866 Static methods in Python are similar to those found in Java or C++.
867 For a more advanced concept, see class methods above.
872 PyObject
*sm_callable
;
876 sm_dealloc(staticmethod
*sm
)
878 _PyObject_GC_UNTRACK((PyObject
*)sm
);
879 Py_XDECREF(sm
->sm_callable
);
880 Py_TYPE(sm
)->tp_free((PyObject
*)sm
);
884 sm_traverse(staticmethod
*sm
, visitproc visit
, void *arg
)
886 Py_VISIT(sm
->sm_callable
);
891 sm_clear(staticmethod
*sm
)
893 Py_XDECREF(sm
->sm_callable
);
894 sm
->sm_callable
= NULL
;
900 sm_descr_get(PyObject
*self
, PyObject
*obj
, PyObject
*type
)
902 staticmethod
*sm
= (staticmethod
*)self
;
904 if (sm
->sm_callable
== NULL
) {
905 PyErr_SetString(PyExc_RuntimeError
,
906 "uninitialized staticmethod object");
909 Py_INCREF(sm
->sm_callable
);
910 return sm
->sm_callable
;
914 sm_init(PyObject
*self
, PyObject
*args
, PyObject
*kwds
)
916 staticmethod
*sm
= (staticmethod
*)self
;
919 if (!PyArg_UnpackTuple(args
, "staticmethod", 1, 1, &callable
))
921 if (!_PyArg_NoKeywords("staticmethod", kwds
))
924 sm
->sm_callable
= callable
;
928 static PyMemberDef sm_memberlist
[] = {
929 {"__func__", T_OBJECT
, offsetof(staticmethod
, sm_callable
), READONLY
},
930 {NULL
} /* Sentinel */
933 PyDoc_STRVAR(staticmethod_doc
,
934 "staticmethod(function) -> method\n\
936 Convert a function to be a static method.\n\
938 A static method does not receive an implicit first argument.\n\
939 To declare a static method, use this idiom:\n\
942 def f(arg1, arg2, ...): ...\n\
943 f = staticmethod(f)\n\
945 It can be called either on the class (e.g. C.f()) or on an instance\n\
946 (e.g. C().f()). The instance is ignored except for its class.\n\
948 Static methods in Python are similar to those found in Java or C++.\n\
949 For a more advanced concept, see the classmethod builtin.");
951 PyTypeObject PyStaticMethod_Type
= {
952 PyVarObject_HEAD_INIT(&PyType_Type
, 0)
954 sizeof(staticmethod
),
956 (destructor
)sm_dealloc
, /* tp_dealloc */
962 0, /* tp_as_number */
963 0, /* tp_as_sequence */
964 0, /* tp_as_mapping */
968 PyObject_GenericGetAttr
, /* tp_getattro */
970 0, /* tp_as_buffer */
971 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC
,
972 staticmethod_doc
, /* tp_doc */
973 (traverseproc
)sm_traverse
, /* tp_traverse */
974 (inquiry
)sm_clear
, /* tp_clear */
975 0, /* tp_richcompare */
976 0, /* tp_weaklistoffset */
980 sm_memberlist
, /* tp_members */
984 sm_descr_get
, /* tp_descr_get */
985 0, /* tp_descr_set */
986 0, /* tp_dictoffset */
987 sm_init
, /* tp_init */
988 PyType_GenericAlloc
, /* tp_alloc */
989 PyType_GenericNew
, /* tp_new */
990 PyObject_GC_Del
, /* tp_free */
994 PyStaticMethod_New(PyObject
*callable
)
996 staticmethod
*sm
= (staticmethod
*)
997 PyType_GenericAlloc(&PyStaticMethod_Type
, 0);
1000 sm
->sm_callable
= callable
;
1002 return (PyObject
*)sm
;