Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Objects/clinic/odictobject.c.h
Line
Count
Source (jump to first uncovered line)
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
PyDoc_STRVAR(OrderedDict_fromkeys__doc__,
6
"fromkeys($type, /, iterable, value=None)\n"
7
"--\n"
8
"\n"
9
"Create a new ordered dictionary with keys from iterable and values set to value.");
10
11
#define ORDEREDDICT_FROMKEYS_METHODDEF    \
12
    {"fromkeys", (PyCFunction)(void(*)(void))OrderedDict_fromkeys, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, OrderedDict_fromkeys__doc__},
13
14
static PyObject *
15
OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value);
16
17
static PyObject *
18
OrderedDict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
19
0
{
20
0
    PyObject *return_value = NULL;
21
0
    static const char * const _keywords[] = {"iterable", "value", NULL};
22
0
    static _PyArg_Parser _parser = {NULL, _keywords, "fromkeys", 0};
23
0
    PyObject *argsbuf[2];
24
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
25
0
    PyObject *seq;
26
0
    PyObject *value = Py_None;
27
28
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
29
0
    if (!args) {
30
0
        goto exit;
31
0
    }
32
0
    seq = args[0];
33
0
    if (!noptargs) {
34
0
        goto skip_optional_pos;
35
0
    }
36
0
    value = args[1];
37
0
skip_optional_pos:
38
0
    return_value = OrderedDict_fromkeys_impl(type, seq, value);
39
40
0
exit:
41
0
    return return_value;
42
0
}
43
44
PyDoc_STRVAR(OrderedDict_setdefault__doc__,
45
"setdefault($self, /, key, default=None)\n"
46
"--\n"
47
"\n"
48
"Insert key with a value of default if key is not in the dictionary.\n"
49
"\n"
50
"Return the value for key if key is in the dictionary, else default.");
51
52
#define ORDEREDDICT_SETDEFAULT_METHODDEF    \
53
    {"setdefault", (PyCFunction)(void(*)(void))OrderedDict_setdefault, METH_FASTCALL|METH_KEYWORDS, OrderedDict_setdefault__doc__},
54
55
static PyObject *
56
OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
57
                            PyObject *default_value);
58
59
static PyObject *
60
OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
61
0
{
62
0
    PyObject *return_value = NULL;
63
0
    static const char * const _keywords[] = {"key", "default", NULL};
64
0
    static _PyArg_Parser _parser = {NULL, _keywords, "setdefault", 0};
65
0
    PyObject *argsbuf[2];
66
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
67
0
    PyObject *key;
68
0
    PyObject *default_value = Py_None;
69
70
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
71
0
    if (!args) {
72
0
        goto exit;
73
0
    }
74
0
    key = args[0];
75
0
    if (!noptargs) {
76
0
        goto skip_optional_pos;
77
0
    }
78
0
    default_value = args[1];
79
0
skip_optional_pos:
80
0
    return_value = OrderedDict_setdefault_impl(self, key, default_value);
81
82
0
exit:
83
0
    return return_value;
84
0
}
85
86
PyDoc_STRVAR(OrderedDict_popitem__doc__,
87
"popitem($self, /, last=True)\n"
88
"--\n"
89
"\n"
90
"Remove and return a (key, value) pair from the dictionary.\n"
91
"\n"
92
"Pairs are returned in LIFO order if last is true or FIFO order if false.");
93
94
#define ORDEREDDICT_POPITEM_METHODDEF    \
95
    {"popitem", (PyCFunction)(void(*)(void))OrderedDict_popitem, METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__},
96
97
static PyObject *
98
OrderedDict_popitem_impl(PyODictObject *self, int last);
99
100
static PyObject *
101
OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
102
0
{
103
0
    PyObject *return_value = NULL;
104
0
    static const char * const _keywords[] = {"last", NULL};
105
0
    static _PyArg_Parser _parser = {NULL, _keywords, "popitem", 0};
106
0
    PyObject *argsbuf[1];
107
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
108
0
    int last = 1;
109
110
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
111
0
    if (!args) {
112
0
        goto exit;
113
0
    }
114
0
    if (!noptargs) {
115
0
        goto skip_optional_pos;
116
0
    }
117
0
    last = PyObject_IsTrue(args[0]);
118
0
    if (last < 0) {
119
0
        goto exit;
120
0
    }
121
0
skip_optional_pos:
122
0
    return_value = OrderedDict_popitem_impl(self, last);
123
124
0
exit:
125
0
    return return_value;
126
0
}
127
128
PyDoc_STRVAR(OrderedDict_move_to_end__doc__,
129
"move_to_end($self, /, key, last=True)\n"
130
"--\n"
131
"\n"
132
"Move an existing element to the end (or beginning if last is false).\n"
133
"\n"
134
"Raise KeyError if the element does not exist.");
135
136
#define ORDEREDDICT_MOVE_TO_END_METHODDEF    \
137
    {"move_to_end", (PyCFunction)(void(*)(void))OrderedDict_move_to_end, METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__},
138
139
static PyObject *
140
OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
141
142
static PyObject *
143
OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
144
0
{
145
0
    PyObject *return_value = NULL;
146
0
    static const char * const _keywords[] = {"key", "last", NULL};
147
0
    static _PyArg_Parser _parser = {NULL, _keywords, "move_to_end", 0};
148
0
    PyObject *argsbuf[2];
149
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
150
0
    PyObject *key;
151
0
    int last = 1;
152
153
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
154
0
    if (!args) {
155
0
        goto exit;
156
0
    }
157
0
    key = args[0];
158
0
    if (!noptargs) {
159
0
        goto skip_optional_pos;
160
0
    }
161
0
    last = PyObject_IsTrue(args[1]);
162
0
    if (last < 0) {
163
0
        goto exit;
164
0
    }
165
0
skip_optional_pos:
166
0
    return_value = OrderedDict_move_to_end_impl(self, key, last);
167
168
0
exit:
169
0
    return return_value;
170
0
}
171
/*[clinic end generated code: output=8eb1296df9142908 input=a9049054013a1b77]*/