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