1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(dict_fromkeys__doc__,
6 "fromkeys($type, iterable, value=None, /)\n"
7 "--\n"
8 "\n"
9 "Create a new dictionary with keys from iterable and values set to value.");
10
11 #define DICT_FROMKEYS_METHODDEF \
12 {"fromkeys", (PyCFunction)(void(*)(void))dict_fromkeys, METH_FASTCALL|METH_CLASS, dict_fromkeys__doc__},
13
14 static PyObject *
15 dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value);
16
17 static PyObject *
dict_fromkeys(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs)18 dict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
19 {
20 PyObject *return_value = NULL;
21 PyObject *iterable;
22 PyObject *value = Py_None;
23
24 if (!_PyArg_CheckPositional("fromkeys", nargs, 1, 2)) {
25 goto exit;
26 }
27 iterable = args[0];
28 if (nargs < 2) {
29 goto skip_optional;
30 }
31 value = args[1];
32 skip_optional:
33 return_value = dict_fromkeys_impl(type, iterable, value);
34
35 exit:
36 return return_value;
37 }
38
39 PyDoc_STRVAR(dict___contains____doc__,
40 "__contains__($self, key, /)\n"
41 "--\n"
42 "\n"
43 "True if the dictionary has the specified key, else False.");
44
45 #define DICT___CONTAINS___METHODDEF \
46 {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__},
47
48 PyDoc_STRVAR(dict_get__doc__,
49 "get($self, key, default=None, /)\n"
50 "--\n"
51 "\n"
52 "Return the value for key if key is in the dictionary, else default.");
53
54 #define DICT_GET_METHODDEF \
55 {"get", (PyCFunction)(void(*)(void))dict_get, METH_FASTCALL, dict_get__doc__},
56
57 static PyObject *
58 dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
59
60 static PyObject *
dict_get(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)61 dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
62 {
63 PyObject *return_value = NULL;
64 PyObject *key;
65 PyObject *default_value = Py_None;
66
67 if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
68 goto exit;
69 }
70 key = args[0];
71 if (nargs < 2) {
72 goto skip_optional;
73 }
74 default_value = args[1];
75 skip_optional:
76 return_value = dict_get_impl(self, key, default_value);
77
78 exit:
79 return return_value;
80 }
81
82 PyDoc_STRVAR(dict_setdefault__doc__,
83 "setdefault($self, key, default=None, /)\n"
84 "--\n"
85 "\n"
86 "Insert key with a value of default if key is not in the dictionary.\n"
87 "\n"
88 "Return the value for key if key is in the dictionary, else default.");
89
90 #define DICT_SETDEFAULT_METHODDEF \
91 {"setdefault", (PyCFunction)(void(*)(void))dict_setdefault, METH_FASTCALL, dict_setdefault__doc__},
92
93 static PyObject *
94 dict_setdefault_impl(PyDictObject *self, PyObject *key,
95 PyObject *default_value);
96
97 static PyObject *
dict_setdefault(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)98 dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
99 {
100 PyObject *return_value = NULL;
101 PyObject *key;
102 PyObject *default_value = Py_None;
103
104 if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) {
105 goto exit;
106 }
107 key = args[0];
108 if (nargs < 2) {
109 goto skip_optional;
110 }
111 default_value = args[1];
112 skip_optional:
113 return_value = dict_setdefault_impl(self, key, default_value);
114
115 exit:
116 return return_value;
117 }
118
119 PyDoc_STRVAR(dict_popitem__doc__,
120 "popitem($self, /)\n"
121 "--\n"
122 "\n"
123 "Remove and return a (key, value) pair as a 2-tuple.\n"
124 "\n"
125 "Pairs are returned in LIFO (last-in, first-out) order.\n"
126 "Raises KeyError if the dict is empty.");
127
128 #define DICT_POPITEM_METHODDEF \
129 {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, dict_popitem__doc__},
130
131 static PyObject *
132 dict_popitem_impl(PyDictObject *self);
133
134 static PyObject *
dict_popitem(PyDictObject * self,PyObject * Py_UNUSED (ignored))135 dict_popitem(PyDictObject *self, PyObject *Py_UNUSED(ignored))
136 {
137 return dict_popitem_impl(self);
138 }
139
140 PyDoc_STRVAR(dict___reversed____doc__,
141 "__reversed__($self, /)\n"
142 "--\n"
143 "\n"
144 "Return a reverse iterator over the dict keys.");
145
146 #define DICT___REVERSED___METHODDEF \
147 {"__reversed__", (PyCFunction)dict___reversed__, METH_NOARGS, dict___reversed____doc__},
148
149 static PyObject *
150 dict___reversed___impl(PyDictObject *self);
151
152 static PyObject *
dict___reversed__(PyDictObject * self,PyObject * Py_UNUSED (ignored))153 dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
154 {
155 return dict___reversed___impl(self);
156 }
157 /*[clinic end generated code: output=676532dcc941d399 input=a9049054013a1b77]*/
158