/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 | | #endif |
8 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
9 | | #include "pycore_runtime.h" // _Py_SINGLETON() |
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_helper(PyTypeObject *type, PyObject *const *args, |
22 | | Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) |
23 | 0 | { |
24 | 0 | PyObject *return_value = NULL; |
25 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
26 | |
|
27 | 0 | #define NUM_KEYWORDS 1 |
28 | 0 | static struct { |
29 | 0 | PyGC_Head _this_is_not_used; |
30 | 0 | PyObject_VAR_HEAD |
31 | 0 | Py_hash_t ob_hash; |
32 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
33 | 0 | } _kwtuple = { |
34 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
35 | 0 | .ob_hash = -1, |
36 | 0 | .ob_item = { &_Py_ID(mapping), }, |
37 | 0 | }; |
38 | 0 | #undef NUM_KEYWORDS |
39 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
40 | |
|
41 | | #else // !Py_BUILD_CORE |
42 | | # define KWTUPLE NULL |
43 | | #endif // !Py_BUILD_CORE |
44 | |
|
45 | 0 | static const char * const _keywords[] = {"mapping", NULL}; |
46 | 0 | static _PyArg_Parser _parser = { |
47 | 0 | .keywords = _keywords, |
48 | 0 | .fname = "mappingproxy", |
49 | 0 | .kwtuple = KWTUPLE, |
50 | 0 | }; |
51 | 0 | #undef KWTUPLE |
52 | 0 | PyObject *argsbuf[1]; |
53 | 0 | PyObject * const *fastargs; |
54 | 0 | PyObject *mapping; |
55 | |
|
56 | 0 | fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, |
57 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
58 | 0 | if (!fastargs) { |
59 | 0 | goto exit; |
60 | 0 | } |
61 | 0 | mapping = fastargs[0]; |
62 | 0 | return_value = mappingproxy_new_impl(type, mapping); |
63 | |
|
64 | 0 | exit: |
65 | 0 | return return_value; |
66 | 0 | } |
67 | | |
68 | | static PyObject * |
69 | | mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
70 | 0 | { |
71 | 0 | return mappingproxy_new_helper(type, _PyTuple_CAST(args)->ob_item, |
72 | 0 | PyTuple_GET_SIZE(args), |
73 | 0 | kwargs ? PyDict_GET_SIZE(kwargs) : 0, |
74 | 0 | kwargs, NULL); |
75 | 0 | } |
76 | | |
77 | | static PyObject * |
78 | | mappingproxy_vectorcall(PyObject *type, PyObject *const *args, |
79 | | size_t nargsf, PyObject *kwnames) |
80 | 983 | { |
81 | 983 | PyObject *return_value = NULL; |
82 | 983 | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
83 | 983 | PyObject *mapping; |
84 | | |
85 | 983 | assert(_PyType_CAST(type)->tp_new == mappingproxy_new); |
86 | | /* Make sure the type object is immutable: the generated |
87 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
88 | 983 | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
89 | 983 | if (kwnames != NULL || nargs < 1 || nargs > 1) { |
90 | 0 | return mappingproxy_new_helper(_PyType_CAST(type), args, nargs, |
91 | 0 | kwnames ? PyTuple_GET_SIZE(kwnames) : 0, |
92 | 0 | NULL, kwnames); |
93 | 0 | } |
94 | 983 | mapping = args[0]; |
95 | 983 | return_value = mappingproxy_new_impl(_PyType_CAST(type), mapping); |
96 | | |
97 | 983 | return return_value; |
98 | 983 | } |
99 | | |
100 | | PyDoc_STRVAR(property___set_name____doc__, |
101 | | "__set_name__($self, owner, name, /)\n" |
102 | | "--\n" |
103 | | "\n" |
104 | | "Method to set name of a property."); |
105 | | |
106 | | #define PROPERTY___SET_NAME___METHODDEF \ |
107 | | {"__set_name__", _PyCFunction_CAST(property___set_name__), METH_FASTCALL, property___set_name____doc__}, |
108 | | |
109 | | static PyObject * |
110 | | property___set_name___impl(propertyobject *self, PyObject *owner, |
111 | | PyObject *name); |
112 | | |
113 | | static PyObject * |
114 | | property___set_name__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
115 | 2.68k | { |
116 | 2.68k | PyObject *return_value = NULL; |
117 | 2.68k | PyObject *owner; |
118 | 2.68k | PyObject *name; |
119 | | |
120 | 2.68k | if (!_PyArg_CheckPositional("__set_name__", nargs, 2, 2)) { |
121 | 0 | goto exit; |
122 | 0 | } |
123 | 2.68k | owner = args[0]; |
124 | 2.68k | name = args[1]; |
125 | 2.68k | return_value = property___set_name___impl((propertyobject *)self, owner, name); |
126 | | |
127 | 2.68k | exit: |
128 | 2.68k | return return_value; |
129 | 2.68k | } |
130 | | |
131 | | PyDoc_STRVAR(property_init__doc__, |
132 | | "property(fget=None, fset=None, fdel=None, doc=None)\n" |
133 | | "--\n" |
134 | | "\n" |
135 | | "Property attribute.\n" |
136 | | "\n" |
137 | | " fget\n" |
138 | | " function to be used for getting an attribute value\n" |
139 | | " fset\n" |
140 | | " function to be used for setting an attribute value\n" |
141 | | " fdel\n" |
142 | | " function to be used for del\'ing an attribute\n" |
143 | | " doc\n" |
144 | | " docstring\n" |
145 | | "\n" |
146 | | "Typical use is to define a managed attribute x:\n" |
147 | | "\n" |
148 | | "class C(object):\n" |
149 | | " def getx(self): return self._x\n" |
150 | | " def setx(self, value): self._x = value\n" |
151 | | " def delx(self): del self._x\n" |
152 | | " x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n" |
153 | | "\n" |
154 | | "Decorators make defining new properties or modifying existing ones easy:\n" |
155 | | "\n" |
156 | | "class C(object):\n" |
157 | | " @property\n" |
158 | | " def x(self):\n" |
159 | | " \"I am the \'x\' property.\"\n" |
160 | | " return self._x\n" |
161 | | " @x.setter\n" |
162 | | " def x(self, value):\n" |
163 | | " self._x = value\n" |
164 | | " @x.deleter\n" |
165 | | " def x(self):\n" |
166 | | " del self._x"); |
167 | | |
168 | | static int |
169 | | property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, |
170 | | PyObject *fdel, PyObject *doc); |
171 | | |
172 | | static int |
173 | | property_init_helper(PyObject *self, PyObject *const *args, |
174 | | Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) |
175 | 0 | { |
176 | 0 | int return_value = -1; |
177 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
178 | |
|
179 | 0 | #define NUM_KEYWORDS 4 |
180 | 0 | static struct { |
181 | 0 | PyGC_Head _this_is_not_used; |
182 | 0 | PyObject_VAR_HEAD |
183 | 0 | Py_hash_t ob_hash; |
184 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
185 | 0 | } _kwtuple = { |
186 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
187 | 0 | .ob_hash = -1, |
188 | 0 | .ob_item = { &_Py_ID(fget), &_Py_ID(fset), &_Py_ID(fdel), &_Py_ID(doc), }, |
189 | 0 | }; |
190 | 0 | #undef NUM_KEYWORDS |
191 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
192 | |
|
193 | | #else // !Py_BUILD_CORE |
194 | | # define KWTUPLE NULL |
195 | | #endif // !Py_BUILD_CORE |
196 | |
|
197 | 0 | static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL}; |
198 | 0 | static _PyArg_Parser _parser = { |
199 | 0 | .keywords = _keywords, |
200 | 0 | .fname = "property", |
201 | 0 | .kwtuple = KWTUPLE, |
202 | 0 | }; |
203 | 0 | #undef KWTUPLE |
204 | 0 | PyObject *argsbuf[4]; |
205 | 0 | PyObject * const *fastargs; |
206 | 0 | Py_ssize_t noptargs = nargs + nkw - 0; |
207 | 0 | PyObject *fget = NULL; |
208 | 0 | PyObject *fset = NULL; |
209 | 0 | PyObject *fdel = NULL; |
210 | 0 | PyObject *doc = NULL; |
211 | |
|
212 | 0 | fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, |
213 | 0 | /*minpos*/ 0, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
214 | 0 | if (!fastargs) { |
215 | 0 | goto exit; |
216 | 0 | } |
217 | 0 | if (!noptargs) { |
218 | 0 | goto skip_optional_pos; |
219 | 0 | } |
220 | 0 | if (fastargs[0]) { |
221 | 0 | fget = fastargs[0]; |
222 | 0 | if (!--noptargs) { |
223 | 0 | goto skip_optional_pos; |
224 | 0 | } |
225 | 0 | } |
226 | 0 | if (fastargs[1]) { |
227 | 0 | fset = fastargs[1]; |
228 | 0 | if (!--noptargs) { |
229 | 0 | goto skip_optional_pos; |
230 | 0 | } |
231 | 0 | } |
232 | 0 | if (fastargs[2]) { |
233 | 0 | fdel = fastargs[2]; |
234 | 0 | if (!--noptargs) { |
235 | 0 | goto skip_optional_pos; |
236 | 0 | } |
237 | 0 | } |
238 | 0 | doc = fastargs[3]; |
239 | 0 | skip_optional_pos: |
240 | 0 | return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc); |
241 | |
|
242 | 0 | exit: |
243 | 0 | return return_value; |
244 | 0 | } |
245 | | |
246 | | static int |
247 | | property_init(PyObject *self, PyObject *args, PyObject *kwargs) |
248 | 0 | { |
249 | 0 | return property_init_helper(self, _PyTuple_CAST(args)->ob_item, |
250 | 0 | PyTuple_GET_SIZE(args), |
251 | 0 | kwargs ? PyDict_GET_SIZE(kwargs) : 0, |
252 | 0 | kwargs, NULL); |
253 | 0 | } |
254 | | |
255 | | static PyObject * |
256 | | property_vectorcall(PyObject *type, PyObject *const *args, |
257 | | size_t nargsf, PyObject *kwnames) |
258 | 2.65k | { |
259 | 2.65k | PyObject *return_value = NULL; |
260 | 2.65k | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
261 | 2.65k | PyObject *self; |
262 | 2.65k | int _result; |
263 | 2.65k | PyObject *fget = NULL; |
264 | 2.65k | PyObject *fset = NULL; |
265 | 2.65k | PyObject *fdel = NULL; |
266 | 2.65k | PyObject *doc = NULL; |
267 | | |
268 | 2.65k | assert(_PyType_CAST(type)->tp_init == property_init); |
269 | | /* Make sure the type object is immutable: the generated |
270 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
271 | 2.65k | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
272 | 2.65k | if (kwnames != NULL || nargs > 4) { |
273 | 0 | self = _PyType_CAST(type)->tp_new(_PyType_CAST(type), |
274 | 0 | (PyObject *)&_Py_SINGLETON(tuple_empty), NULL); |
275 | 0 | if (self == NULL) { |
276 | 0 | return NULL; |
277 | 0 | } |
278 | 0 | _result = property_init_helper(self, args, nargs, |
279 | 0 | kwnames ? PyTuple_GET_SIZE(kwnames) : 0, |
280 | 0 | NULL, kwnames); |
281 | 0 | if (_result != 0) { |
282 | 0 | Py_DECREF(self); |
283 | 0 | return NULL; |
284 | 0 | } |
285 | 0 | return self; |
286 | 0 | } |
287 | 2.65k | if (nargs < 1) { |
288 | 0 | goto skip_optional; |
289 | 0 | } |
290 | 2.65k | fget = args[0]; |
291 | 2.65k | if (nargs < 2) { |
292 | 2.47k | goto skip_optional; |
293 | 2.47k | } |
294 | 181 | fset = args[1]; |
295 | 181 | if (nargs < 3) { |
296 | 9 | goto skip_optional; |
297 | 9 | } |
298 | 172 | fdel = args[2]; |
299 | 172 | if (nargs < 4) { |
300 | 0 | goto skip_optional; |
301 | 0 | } |
302 | 172 | doc = args[3]; |
303 | 2.65k | skip_optional: |
304 | 2.65k | self = _PyType_CAST(type)->tp_new(_PyType_CAST(type), |
305 | 2.65k | (PyObject *)&_Py_SINGLETON(tuple_empty), NULL); |
306 | 2.65k | if (self == NULL) { |
307 | 0 | goto exit; |
308 | 0 | } |
309 | 2.65k | _result = property_init_impl((propertyobject *)self, fget, fset, fdel, doc); |
310 | 2.65k | if (_result != 0) { |
311 | 0 | Py_DECREF(self); |
312 | 0 | goto exit; |
313 | 0 | } |
314 | 2.65k | return_value = self; |
315 | | |
316 | 2.65k | exit: |
317 | 2.65k | return return_value; |
318 | 2.65k | } |
319 | | /*[clinic end generated code: output=cd59da11d2fc4f7c input=a9049054013a1b77]*/ |