Branch data Line data Source code
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 : : PyDoc_STRVAR(dict_fromkeys__doc__,
12 : : "fromkeys($type, iterable, value=None, /)\n"
13 : : "--\n"
14 : : "\n"
15 : : "Create a new dictionary with keys from iterable and values set to value.");
16 : :
17 : : #define DICT_FROMKEYS_METHODDEF \
18 : : {"fromkeys", _PyCFunction_CAST(dict_fromkeys), METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__},
19 : :
20 : : static PyObject *
21 : : dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value);
22 : :
23 : : static PyObject *
24 : 152 : dict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
25 : : {
26 : 152 : PyObject *return_value = NULL;
27 : : PyObject *iterable;
28 : 152 : PyObject *value = Py_None;
29 : :
30 [ + - - + : 152 : if (!_PyArg_CheckPositional("fromkeys", nargs, 1, 2)) {
- - ]
31 : 0 : goto exit;
32 : : }
33 : 152 : iterable = args[0];
34 [ + + ]: 152 : if (nargs < 2) {
35 : 150 : goto skip_optional;
36 : : }
37 : 2 : value = args[1];
38 : 152 : skip_optional:
39 : 152 : return_value = dict_fromkeys_impl(type, iterable, value);
40 : :
41 : 152 : exit:
42 : 152 : return return_value;
43 : : }
44 : :
45 : : PyDoc_STRVAR(dict___contains____doc__,
46 : : "__contains__($self, key, /)\n"
47 : : "--\n"
48 : : "\n"
49 : : "True if the dictionary has the specified key, else False.");
50 : :
51 : : #define DICT___CONTAINS___METHODDEF \
52 : : {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__},
53 : :
54 : : PyDoc_STRVAR(dict_get__doc__,
55 : : "get($self, key, default=None, /)\n"
56 : : "--\n"
57 : : "\n"
58 : : "Return the value for key if key is in the dictionary, else default.");
59 : :
60 : : #define DICT_GET_METHODDEF \
61 : : {"get", _PyCFunction_CAST(dict_get), METH_FASTCALL, dict_get__doc__},
62 : :
63 : : static PyObject *
64 : : dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
65 : :
66 : : static PyObject *
67 : 132694 : dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
68 : : {
69 : 132694 : PyObject *return_value = NULL;
70 : : PyObject *key;
71 : 132694 : PyObject *default_value = Py_None;
72 : :
73 [ + - - + : 132694 : if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
- - ]
74 : 0 : goto exit;
75 : : }
76 : 132694 : key = args[0];
77 [ + + ]: 132694 : if (nargs < 2) {
78 : 128523 : goto skip_optional;
79 : : }
80 : 4171 : default_value = args[1];
81 : 132694 : skip_optional:
82 : 132694 : return_value = dict_get_impl(self, key, default_value);
83 : :
84 : 132694 : exit:
85 : 132694 : return return_value;
86 : : }
87 : :
88 : : PyDoc_STRVAR(dict_setdefault__doc__,
89 : : "setdefault($self, key, default=None, /)\n"
90 : : "--\n"
91 : : "\n"
92 : : "Insert key with a value of default if key is not in the dictionary.\n"
93 : : "\n"
94 : : "Return the value for key if key is in the dictionary, else default.");
95 : :
96 : : #define DICT_SETDEFAULT_METHODDEF \
97 : : {"setdefault", _PyCFunction_CAST(dict_setdefault), METH_FASTCALL, dict_setdefault__doc__},
98 : :
99 : : static PyObject *
100 : : dict_setdefault_impl(PyDictObject *self, PyObject *key,
101 : : PyObject *default_value);
102 : :
103 : : static PyObject *
104 : 1723 : dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
105 : : {
106 : 1723 : PyObject *return_value = NULL;
107 : : PyObject *key;
108 : 1723 : PyObject *default_value = Py_None;
109 : :
110 [ + - - + : 1723 : if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) {
- - ]
111 : 0 : goto exit;
112 : : }
113 : 1723 : key = args[0];
114 [ - + ]: 1723 : if (nargs < 2) {
115 : 0 : goto skip_optional;
116 : : }
117 : 1723 : default_value = args[1];
118 : 1723 : skip_optional:
119 : 1723 : return_value = dict_setdefault_impl(self, key, default_value);
120 : :
121 : 1723 : exit:
122 : 1723 : return return_value;
123 : : }
124 : :
125 : : PyDoc_STRVAR(dict_pop__doc__,
126 : : "pop($self, key, default=<unrepresentable>, /)\n"
127 : : "--\n"
128 : : "\n"
129 : : "D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n"
130 : : "\n"
131 : : "If the key is not found, return the default if given; otherwise,\n"
132 : : "raise a KeyError.");
133 : :
134 : : #define DICT_POP_METHODDEF \
135 : : {"pop", _PyCFunction_CAST(dict_pop), METH_FASTCALL, dict_pop__doc__},
136 : :
137 : : static PyObject *
138 : : dict_pop_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
139 : :
140 : : static PyObject *
141 : 1427 : dict_pop(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
142 : : {
143 : 1427 : PyObject *return_value = NULL;
144 : : PyObject *key;
145 : 1427 : PyObject *default_value = NULL;
146 : :
147 [ + - - + : 1427 : if (!_PyArg_CheckPositional("pop", nargs, 1, 2)) {
- - ]
148 : 0 : goto exit;
149 : : }
150 : 1427 : key = args[0];
151 [ + + ]: 1427 : if (nargs < 2) {
152 : 1076 : goto skip_optional;
153 : : }
154 : 351 : default_value = args[1];
155 : 1427 : skip_optional:
156 : 1427 : return_value = dict_pop_impl(self, key, default_value);
157 : :
158 : 1427 : exit:
159 : 1427 : return return_value;
160 : : }
161 : :
162 : : PyDoc_STRVAR(dict_popitem__doc__,
163 : : "popitem($self, /)\n"
164 : : "--\n"
165 : : "\n"
166 : : "Remove and return a (key, value) pair as a 2-tuple.\n"
167 : : "\n"
168 : : "Pairs are returned in LIFO (last-in, first-out) order.\n"
169 : : "Raises KeyError if the dict is empty.");
170 : :
171 : : #define DICT_POPITEM_METHODDEF \
172 : : {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__},
173 : :
174 : : static PyObject *
175 : : dict_popitem_impl(PyDictObject *self);
176 : :
177 : : static PyObject *
178 : 0 : dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored))
179 : : {
180 : 0 : return dict_popitem_impl(self);
181 : : }
182 : :
183 : : PyDoc_STRVAR(dict___reversed____doc__,
184 : : "__reversed__($self, /)\n"
185 : : "--\n"
186 : : "\n"
187 : : "Return a reverse iterator over the dict keys.");
188 : :
189 : : #define DICT___REVERSED___METHODDEF \
190 : : {"__reversed__", (PyCFunction)dict___reversed__, METH_NOARGS, dict___reversed____doc__},
191 : :
192 : : static PyObject *
193 : : dict___reversed___impl(PyDictObject *self);
194 : :
195 : : static PyObject *
196 : 0 : dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
197 : : {
198 : 0 : return dict___reversed___impl(self);
199 : : }
200 : : /*[clinic end generated code: output=c0064abbea6091c5 input=a9049054013a1b77]*/
|