• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)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_UnpackStack(args, nargs, "fromkeys",
25         1, 2,
26         &iterable, &value)) {
27         goto exit;
28     }
29     return_value = dict_fromkeys_impl(type, iterable, value);
30 
31 exit:
32     return return_value;
33 }
34 
35 PyDoc_STRVAR(dict___contains____doc__,
36 "__contains__($self, key, /)\n"
37 "--\n"
38 "\n"
39 "True if the dictionary has the specified key, else False.");
40 
41 #define DICT___CONTAINS___METHODDEF    \
42     {"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__},
43 
44 PyDoc_STRVAR(dict_get__doc__,
45 "get($self, key, default=None, /)\n"
46 "--\n"
47 "\n"
48 "Return the value for key if key is in the dictionary, else default.");
49 
50 #define DICT_GET_METHODDEF    \
51     {"get", (PyCFunction)dict_get, METH_FASTCALL, dict_get__doc__},
52 
53 static PyObject *
54 dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value);
55 
56 static PyObject *
dict_get(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)57 dict_get(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
58 {
59     PyObject *return_value = NULL;
60     PyObject *key;
61     PyObject *default_value = Py_None;
62 
63     if (!_PyArg_UnpackStack(args, nargs, "get",
64         1, 2,
65         &key, &default_value)) {
66         goto exit;
67     }
68     return_value = dict_get_impl(self, key, default_value);
69 
70 exit:
71     return return_value;
72 }
73 
74 PyDoc_STRVAR(dict_setdefault__doc__,
75 "setdefault($self, key, default=None, /)\n"
76 "--\n"
77 "\n"
78 "Insert key with a value of default if key is not in the dictionary.\n"
79 "\n"
80 "Return the value for key if key is in the dictionary, else default.");
81 
82 #define DICT_SETDEFAULT_METHODDEF    \
83     {"setdefault", (PyCFunction)dict_setdefault, METH_FASTCALL, dict_setdefault__doc__},
84 
85 static PyObject *
86 dict_setdefault_impl(PyDictObject *self, PyObject *key,
87                      PyObject *default_value);
88 
89 static PyObject *
dict_setdefault(PyDictObject * self,PyObject * const * args,Py_ssize_t nargs)90 dict_setdefault(PyDictObject *self, PyObject *const *args, Py_ssize_t nargs)
91 {
92     PyObject *return_value = NULL;
93     PyObject *key;
94     PyObject *default_value = Py_None;
95 
96     if (!_PyArg_UnpackStack(args, nargs, "setdefault",
97         1, 2,
98         &key, &default_value)) {
99         goto exit;
100     }
101     return_value = dict_setdefault_impl(self, key, default_value);
102 
103 exit:
104     return return_value;
105 }
106 /*[clinic end generated code: output=d7508c5091609a23 input=a9049054013a1b77]*/
107