descrobject.c.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. static PyObject *
  9. mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
  10. static PyObject *
  11. mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  12. {
  13. PyObject *return_value = NULL;
  14. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  15. #define NUM_KEYWORDS 1
  16. static struct {
  17. PyGC_Head _this_is_not_used;
  18. PyObject_VAR_HEAD
  19. PyObject *ob_item[NUM_KEYWORDS];
  20. } _kwtuple = {
  21. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  22. .ob_item = { &_Py_ID(mapping), },
  23. };
  24. #undef NUM_KEYWORDS
  25. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  26. #else // !Py_BUILD_CORE
  27. # define KWTUPLE NULL
  28. #endif // !Py_BUILD_CORE
  29. static const char * const _keywords[] = {"mapping", NULL};
  30. static _PyArg_Parser _parser = {
  31. .keywords = _keywords,
  32. .fname = "mappingproxy",
  33. .kwtuple = KWTUPLE,
  34. };
  35. #undef KWTUPLE
  36. PyObject *argsbuf[1];
  37. PyObject * const *fastargs;
  38. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  39. PyObject *mapping;
  40. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
  41. if (!fastargs) {
  42. goto exit;
  43. }
  44. mapping = fastargs[0];
  45. return_value = mappingproxy_new_impl(type, mapping);
  46. exit:
  47. return return_value;
  48. }
  49. PyDoc_STRVAR(property_init__doc__,
  50. "property(fget=None, fset=None, fdel=None, doc=None)\n"
  51. "--\n"
  52. "\n"
  53. "Property attribute.\n"
  54. "\n"
  55. " fget\n"
  56. " function to be used for getting an attribute value\n"
  57. " fset\n"
  58. " function to be used for setting an attribute value\n"
  59. " fdel\n"
  60. " function to be used for del\'ing an attribute\n"
  61. " doc\n"
  62. " docstring\n"
  63. "\n"
  64. "Typical use is to define a managed attribute x:\n"
  65. "\n"
  66. "class C(object):\n"
  67. " def getx(self): return self._x\n"
  68. " def setx(self, value): self._x = value\n"
  69. " def delx(self): del self._x\n"
  70. " x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n"
  71. "\n"
  72. "Decorators make defining new properties or modifying existing ones easy:\n"
  73. "\n"
  74. "class C(object):\n"
  75. " @property\n"
  76. " def x(self):\n"
  77. " \"I am the \'x\' property.\"\n"
  78. " return self._x\n"
  79. " @x.setter\n"
  80. " def x(self, value):\n"
  81. " self._x = value\n"
  82. " @x.deleter\n"
  83. " def x(self):\n"
  84. " del self._x");
  85. static int
  86. property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
  87. PyObject *fdel, PyObject *doc);
  88. static int
  89. property_init(PyObject *self, PyObject *args, PyObject *kwargs)
  90. {
  91. int return_value = -1;
  92. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  93. #define NUM_KEYWORDS 4
  94. static struct {
  95. PyGC_Head _this_is_not_used;
  96. PyObject_VAR_HEAD
  97. PyObject *ob_item[NUM_KEYWORDS];
  98. } _kwtuple = {
  99. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  100. .ob_item = { &_Py_ID(fget), &_Py_ID(fset), &_Py_ID(fdel), &_Py_ID(doc), },
  101. };
  102. #undef NUM_KEYWORDS
  103. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  104. #else // !Py_BUILD_CORE
  105. # define KWTUPLE NULL
  106. #endif // !Py_BUILD_CORE
  107. static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL};
  108. static _PyArg_Parser _parser = {
  109. .keywords = _keywords,
  110. .fname = "property",
  111. .kwtuple = KWTUPLE,
  112. };
  113. #undef KWTUPLE
  114. PyObject *argsbuf[4];
  115. PyObject * const *fastargs;
  116. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  117. Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
  118. PyObject *fget = NULL;
  119. PyObject *fset = NULL;
  120. PyObject *fdel = NULL;
  121. PyObject *doc = NULL;
  122. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 4, 0, argsbuf);
  123. if (!fastargs) {
  124. goto exit;
  125. }
  126. if (!noptargs) {
  127. goto skip_optional_pos;
  128. }
  129. if (fastargs[0]) {
  130. fget = fastargs[0];
  131. if (!--noptargs) {
  132. goto skip_optional_pos;
  133. }
  134. }
  135. if (fastargs[1]) {
  136. fset = fastargs[1];
  137. if (!--noptargs) {
  138. goto skip_optional_pos;
  139. }
  140. }
  141. if (fastargs[2]) {
  142. fdel = fastargs[2];
  143. if (!--noptargs) {
  144. goto skip_optional_pos;
  145. }
  146. }
  147. doc = fastargs[3];
  148. skip_optional_pos:
  149. return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc);
  150. exit:
  151. return return_value;
  152. }
  153. /*[clinic end generated code: output=8dc1ddfcf764ac8e input=a9049054013a1b77]*/