classobject.c.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(method___reduce____doc__,
  9. "__reduce__($self, /)\n"
  10. "--\n"
  11. "\n");
  12. #define METHOD___REDUCE___METHODDEF \
  13. {"__reduce__", (PyCFunction)method___reduce__, METH_NOARGS, method___reduce____doc__},
  14. static PyObject *
  15. method___reduce___impl(PyMethodObject *self);
  16. static PyObject *
  17. method___reduce__(PyMethodObject *self, PyObject *Py_UNUSED(ignored))
  18. {
  19. return method___reduce___impl(self);
  20. }
  21. PyDoc_STRVAR(method_new__doc__,
  22. "method(function, instance, /)\n"
  23. "--\n"
  24. "\n"
  25. "Create a bound instance method object.");
  26. static PyObject *
  27. method_new_impl(PyTypeObject *type, PyObject *function, PyObject *instance);
  28. static PyObject *
  29. method_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  30. {
  31. PyObject *return_value = NULL;
  32. PyTypeObject *base_tp = &PyMethod_Type;
  33. PyObject *function;
  34. PyObject *instance;
  35. if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
  36. !_PyArg_NoKeywords("method", kwargs)) {
  37. goto exit;
  38. }
  39. if (!_PyArg_CheckPositional("method", PyTuple_GET_SIZE(args), 2, 2)) {
  40. goto exit;
  41. }
  42. function = PyTuple_GET_ITEM(args, 0);
  43. instance = PyTuple_GET_ITEM(args, 1);
  44. return_value = method_new_impl(type, function, instance);
  45. exit:
  46. return return_value;
  47. }
  48. PyDoc_STRVAR(instancemethod_new__doc__,
  49. "instancemethod(function, /)\n"
  50. "--\n"
  51. "\n"
  52. "Bind a function to a class.");
  53. static PyObject *
  54. instancemethod_new_impl(PyTypeObject *type, PyObject *function);
  55. static PyObject *
  56. instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  57. {
  58. PyObject *return_value = NULL;
  59. PyTypeObject *base_tp = &PyInstanceMethod_Type;
  60. PyObject *function;
  61. if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
  62. !_PyArg_NoKeywords("instancemethod", kwargs)) {
  63. goto exit;
  64. }
  65. if (!_PyArg_CheckPositional("instancemethod", PyTuple_GET_SIZE(args), 1, 1)) {
  66. goto exit;
  67. }
  68. function = PyTuple_GET_ITEM(args, 0);
  69. return_value = instancemethod_new_impl(type, function);
  70. exit:
  71. return return_value;
  72. }
  73. /*[clinic end generated code: output=2a5e7fa5947a86cb input=a9049054013a1b77]*/