/src/cpython/Objects/clinic/descrobject.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
10 | | |
11 | | PyDoc_STRVAR(mappingproxy_new__doc__, |
12 | | "mappingproxy(mapping)\n" |
13 | | "--\n" |
14 | | "\n" |
15 | | "Read-only proxy of a mapping."); |
16 | | |
17 | | static PyObject * |
18 | | mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping); |
19 | | |
20 | | static PyObject * |
21 | | mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
22 | 16.6k | { |
23 | 16.6k | PyObject *return_value = NULL; |
24 | 16.6k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
25 | | |
26 | 16.6k | #define NUM_KEYWORDS 1 |
27 | 16.6k | static struct { |
28 | 16.6k | PyGC_Head _this_is_not_used; |
29 | 16.6k | PyObject_VAR_HEAD |
30 | 16.6k | Py_hash_t ob_hash; |
31 | 16.6k | PyObject *ob_item[NUM_KEYWORDS]; |
32 | 16.6k | } _kwtuple = { |
33 | 16.6k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
34 | 16.6k | .ob_hash = -1, |
35 | 16.6k | .ob_item = { &_Py_ID(mapping), }, |
36 | 16.6k | }; |
37 | 16.6k | #undef NUM_KEYWORDS |
38 | 16.6k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
39 | | |
40 | | #else // !Py_BUILD_CORE |
41 | | # define KWTUPLE NULL |
42 | | #endif // !Py_BUILD_CORE |
43 | | |
44 | 16.6k | static const char * const _keywords[] = {"mapping", NULL}; |
45 | 16.6k | static _PyArg_Parser _parser = { |
46 | 16.6k | .keywords = _keywords, |
47 | 16.6k | .fname = "mappingproxy", |
48 | 16.6k | .kwtuple = KWTUPLE, |
49 | 16.6k | }; |
50 | 16.6k | #undef KWTUPLE |
51 | 16.6k | PyObject *argsbuf[1]; |
52 | 16.6k | PyObject * const *fastargs; |
53 | 16.6k | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
54 | 16.6k | PyObject *mapping; |
55 | | |
56 | 16.6k | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
57 | 16.6k | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
58 | 16.6k | if (!fastargs) { |
59 | 0 | goto exit; |
60 | 0 | } |
61 | 16.6k | mapping = fastargs[0]; |
62 | 16.6k | return_value = mappingproxy_new_impl(type, mapping); |
63 | | |
64 | 16.6k | exit: |
65 | 16.6k | return return_value; |
66 | 16.6k | } |
67 | | |
68 | | PyDoc_STRVAR(property___set_name____doc__, |
69 | | "__set_name__($self, owner, name, /)\n" |
70 | | "--\n" |
71 | | "\n" |
72 | | "Method to set name of a property."); |
73 | | |
74 | | #define PROPERTY___SET_NAME___METHODDEF \ |
75 | | {"__set_name__", _PyCFunction_CAST(property___set_name__), METH_FASTCALL, property___set_name____doc__}, |
76 | | |
77 | | static PyObject * |
78 | | property___set_name___impl(propertyobject *self, PyObject *owner, |
79 | | PyObject *name); |
80 | | |
81 | | static PyObject * |
82 | | property___set_name__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
83 | 2.88k | { |
84 | 2.88k | PyObject *return_value = NULL; |
85 | 2.88k | PyObject *owner; |
86 | 2.88k | PyObject *name; |
87 | | |
88 | 2.88k | if (!_PyArg_CheckPositional("__set_name__", nargs, 2, 2)) { |
89 | 0 | goto exit; |
90 | 0 | } |
91 | 2.88k | owner = args[0]; |
92 | 2.88k | name = args[1]; |
93 | 2.88k | return_value = property___set_name___impl((propertyobject *)self, owner, name); |
94 | | |
95 | 2.88k | exit: |
96 | 2.88k | return return_value; |
97 | 2.88k | } |
98 | | |
99 | | PyDoc_STRVAR(property_init__doc__, |
100 | | "property(fget=None, fset=None, fdel=None, doc=None)\n" |
101 | | "--\n" |
102 | | "\n" |
103 | | "Property attribute.\n" |
104 | | "\n" |
105 | | " fget\n" |
106 | | " function to be used for getting an attribute value\n" |
107 | | " fset\n" |
108 | | " function to be used for setting an attribute value\n" |
109 | | " fdel\n" |
110 | | " function to be used for del\'ing an attribute\n" |
111 | | " doc\n" |
112 | | " docstring\n" |
113 | | "\n" |
114 | | "Typical use is to define a managed attribute x:\n" |
115 | | "\n" |
116 | | "class C(object):\n" |
117 | | " def getx(self): return self._x\n" |
118 | | " def setx(self, value): self._x = value\n" |
119 | | " def delx(self): del self._x\n" |
120 | | " x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n" |
121 | | "\n" |
122 | | "Decorators make defining new properties or modifying existing ones easy:\n" |
123 | | "\n" |
124 | | "class C(object):\n" |
125 | | " @property\n" |
126 | | " def x(self):\n" |
127 | | " \"I am the \'x\' property.\"\n" |
128 | | " return self._x\n" |
129 | | " @x.setter\n" |
130 | | " def x(self, value):\n" |
131 | | " self._x = value\n" |
132 | | " @x.deleter\n" |
133 | | " def x(self):\n" |
134 | | " del self._x"); |
135 | | |
136 | | static int |
137 | | property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, |
138 | | PyObject *fdel, PyObject *doc); |
139 | | |
140 | | static int |
141 | | property_init(PyObject *self, PyObject *args, PyObject *kwargs) |
142 | 2.90k | { |
143 | 2.90k | int return_value = -1; |
144 | 2.90k | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
145 | | |
146 | 2.90k | #define NUM_KEYWORDS 4 |
147 | 2.90k | static struct { |
148 | 2.90k | PyGC_Head _this_is_not_used; |
149 | 2.90k | PyObject_VAR_HEAD |
150 | 2.90k | Py_hash_t ob_hash; |
151 | 2.90k | PyObject *ob_item[NUM_KEYWORDS]; |
152 | 2.90k | } _kwtuple = { |
153 | 2.90k | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
154 | 2.90k | .ob_hash = -1, |
155 | 2.90k | .ob_item = { &_Py_ID(fget), &_Py_ID(fset), &_Py_ID(fdel), &_Py_ID(doc), }, |
156 | 2.90k | }; |
157 | 2.90k | #undef NUM_KEYWORDS |
158 | 2.90k | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
159 | | |
160 | | #else // !Py_BUILD_CORE |
161 | | # define KWTUPLE NULL |
162 | | #endif // !Py_BUILD_CORE |
163 | | |
164 | 2.90k | static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL}; |
165 | 2.90k | static _PyArg_Parser _parser = { |
166 | 2.90k | .keywords = _keywords, |
167 | 2.90k | .fname = "property", |
168 | 2.90k | .kwtuple = KWTUPLE, |
169 | 2.90k | }; |
170 | 2.90k | #undef KWTUPLE |
171 | 2.90k | PyObject *argsbuf[4]; |
172 | 2.90k | PyObject * const *fastargs; |
173 | 2.90k | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
174 | 2.90k | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
175 | 2.90k | PyObject *fget = NULL; |
176 | 2.90k | PyObject *fset = NULL; |
177 | 2.90k | PyObject *fdel = NULL; |
178 | 2.90k | PyObject *doc = NULL; |
179 | | |
180 | 2.90k | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
181 | 2.90k | /*minpos*/ 0, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
182 | 2.90k | if (!fastargs) { |
183 | 0 | goto exit; |
184 | 0 | } |
185 | 2.90k | if (!noptargs) { |
186 | 0 | goto skip_optional_pos; |
187 | 0 | } |
188 | 2.90k | if (fastargs[0]) { |
189 | 2.90k | fget = fastargs[0]; |
190 | 2.90k | if (!--noptargs) { |
191 | 2.61k | goto skip_optional_pos; |
192 | 2.61k | } |
193 | 2.90k | } |
194 | 285 | if (fastargs[1]) { |
195 | 285 | fset = fastargs[1]; |
196 | 285 | if (!--noptargs) { |
197 | 45 | goto skip_optional_pos; |
198 | 45 | } |
199 | 285 | } |
200 | 240 | if (fastargs[2]) { |
201 | 236 | fdel = fastargs[2]; |
202 | 236 | if (!--noptargs) { |
203 | 0 | goto skip_optional_pos; |
204 | 0 | } |
205 | 236 | } |
206 | 240 | doc = fastargs[3]; |
207 | 2.90k | skip_optional_pos: |
208 | 2.90k | return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc); |
209 | | |
210 | 2.90k | exit: |
211 | 2.90k | return return_value; |
212 | 2.90k | } |
213 | | /*[clinic end generated code: output=fb62ee8be13af793 input=a9049054013a1b77]*/ |