Coverage Report

Created: 2025-07-04 06:49

/src/cpython/Python/clinic/context.c.h
Line
Count
Source (jump to first uncovered line)
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
6
7
PyDoc_STRVAR(_contextvars_Context_get__doc__,
8
"get($self, key, default=None, /)\n"
9
"--\n"
10
"\n"
11
"Return the value for `key` if `key` has the value in the context object.\n"
12
"\n"
13
"If `key` does not exist, return `default`. If `default` is not given,\n"
14
"return None.");
15
16
#define _CONTEXTVARS_CONTEXT_GET_METHODDEF    \
17
    {"get", _PyCFunction_CAST(_contextvars_Context_get), METH_FASTCALL, _contextvars_Context_get__doc__},
18
19
static PyObject *
20
_contextvars_Context_get_impl(PyContext *self, PyObject *key,
21
                              PyObject *default_value);
22
23
static PyObject *
24
_contextvars_Context_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
25
0
{
26
0
    PyObject *return_value = NULL;
27
0
    PyObject *key;
28
0
    PyObject *default_value = Py_None;
29
30
0
    if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
31
0
        goto exit;
32
0
    }
33
0
    key = args[0];
34
0
    if (nargs < 2) {
35
0
        goto skip_optional;
36
0
    }
37
0
    default_value = args[1];
38
0
skip_optional:
39
0
    return_value = _contextvars_Context_get_impl((PyContext *)self, key, default_value);
40
41
0
exit:
42
0
    return return_value;
43
0
}
44
45
PyDoc_STRVAR(_contextvars_Context_items__doc__,
46
"items($self, /)\n"
47
"--\n"
48
"\n"
49
"Return all variables and their values in the context object.\n"
50
"\n"
51
"The result is returned as a list of 2-tuples (variable, value).");
52
53
#define _CONTEXTVARS_CONTEXT_ITEMS_METHODDEF    \
54
    {"items", (PyCFunction)_contextvars_Context_items, METH_NOARGS, _contextvars_Context_items__doc__},
55
56
static PyObject *
57
_contextvars_Context_items_impl(PyContext *self);
58
59
static PyObject *
60
_contextvars_Context_items(PyObject *self, PyObject *Py_UNUSED(ignored))
61
0
{
62
0
    return _contextvars_Context_items_impl((PyContext *)self);
63
0
}
64
65
PyDoc_STRVAR(_contextvars_Context_keys__doc__,
66
"keys($self, /)\n"
67
"--\n"
68
"\n"
69
"Return a list of all variables in the context object.");
70
71
#define _CONTEXTVARS_CONTEXT_KEYS_METHODDEF    \
72
    {"keys", (PyCFunction)_contextvars_Context_keys, METH_NOARGS, _contextvars_Context_keys__doc__},
73
74
static PyObject *
75
_contextvars_Context_keys_impl(PyContext *self);
76
77
static PyObject *
78
_contextvars_Context_keys(PyObject *self, PyObject *Py_UNUSED(ignored))
79
0
{
80
0
    return _contextvars_Context_keys_impl((PyContext *)self);
81
0
}
82
83
PyDoc_STRVAR(_contextvars_Context_values__doc__,
84
"values($self, /)\n"
85
"--\n"
86
"\n"
87
"Return a list of all variables\' values in the context object.");
88
89
#define _CONTEXTVARS_CONTEXT_VALUES_METHODDEF    \
90
    {"values", (PyCFunction)_contextvars_Context_values, METH_NOARGS, _contextvars_Context_values__doc__},
91
92
static PyObject *
93
_contextvars_Context_values_impl(PyContext *self);
94
95
static PyObject *
96
_contextvars_Context_values(PyObject *self, PyObject *Py_UNUSED(ignored))
97
0
{
98
0
    return _contextvars_Context_values_impl((PyContext *)self);
99
0
}
100
101
PyDoc_STRVAR(_contextvars_Context_copy__doc__,
102
"copy($self, /)\n"
103
"--\n"
104
"\n"
105
"Return a shallow copy of the context object.");
106
107
#define _CONTEXTVARS_CONTEXT_COPY_METHODDEF    \
108
    {"copy", (PyCFunction)_contextvars_Context_copy, METH_NOARGS, _contextvars_Context_copy__doc__},
109
110
static PyObject *
111
_contextvars_Context_copy_impl(PyContext *self);
112
113
static PyObject *
114
_contextvars_Context_copy(PyObject *self, PyObject *Py_UNUSED(ignored))
115
0
{
116
0
    return _contextvars_Context_copy_impl((PyContext *)self);
117
0
}
118
119
PyDoc_STRVAR(_contextvars_ContextVar_get__doc__,
120
"get($self, default=<unrepresentable>, /)\n"
121
"--\n"
122
"\n"
123
"Return a value for the context variable for the current context.\n"
124
"\n"
125
"If there is no value for the variable in the current context, the method will:\n"
126
" * return the value of the default argument of the method, if provided; or\n"
127
" * return the default value for the context variable, if it was created\n"
128
"   with one; or\n"
129
" * raise a LookupError.");
130
131
#define _CONTEXTVARS_CONTEXTVAR_GET_METHODDEF    \
132
    {"get", _PyCFunction_CAST(_contextvars_ContextVar_get), METH_FASTCALL, _contextvars_ContextVar_get__doc__},
133
134
static PyObject *
135
_contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value);
136
137
static PyObject *
138
_contextvars_ContextVar_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
139
0
{
140
0
    PyObject *return_value = NULL;
141
0
    PyObject *default_value = NULL;
142
143
0
    if (!_PyArg_CheckPositional("get", nargs, 0, 1)) {
144
0
        goto exit;
145
0
    }
146
0
    if (nargs < 1) {
147
0
        goto skip_optional;
148
0
    }
149
0
    default_value = args[0];
150
0
skip_optional:
151
0
    return_value = _contextvars_ContextVar_get_impl((PyContextVar *)self, default_value);
152
153
0
exit:
154
0
    return return_value;
155
0
}
156
157
PyDoc_STRVAR(_contextvars_ContextVar_set__doc__,
158
"set($self, value, /)\n"
159
"--\n"
160
"\n"
161
"Call to set a new value for the context variable in the current context.\n"
162
"\n"
163
"The required value argument is the new value for the context variable.\n"
164
"\n"
165
"Returns a Token object that can be used to restore the variable to its previous\n"
166
"value via the `ContextVar.reset()` method.");
167
168
#define _CONTEXTVARS_CONTEXTVAR_SET_METHODDEF    \
169
    {"set", (PyCFunction)_contextvars_ContextVar_set, METH_O, _contextvars_ContextVar_set__doc__},
170
171
static PyObject *
172
_contextvars_ContextVar_set_impl(PyContextVar *self, PyObject *value);
173
174
static PyObject *
175
_contextvars_ContextVar_set(PyObject *self, PyObject *value)
176
0
{
177
0
    PyObject *return_value = NULL;
178
179
0
    return_value = _contextvars_ContextVar_set_impl((PyContextVar *)self, value);
180
181
0
    return return_value;
182
0
}
183
184
PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__,
185
"reset($self, token, /)\n"
186
"--\n"
187
"\n"
188
"Reset the context variable.\n"
189
"\n"
190
"The variable is reset to the value it had before the `ContextVar.set()` that\n"
191
"created the token was used.");
192
193
#define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF    \
194
    {"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__},
195
196
static PyObject *
197
_contextvars_ContextVar_reset_impl(PyContextVar *self, PyObject *token);
198
199
static PyObject *
200
_contextvars_ContextVar_reset(PyObject *self, PyObject *token)
201
0
{
202
0
    PyObject *return_value = NULL;
203
204
0
    return_value = _contextvars_ContextVar_reset_impl((PyContextVar *)self, token);
205
206
0
    return return_value;
207
0
}
208
209
PyDoc_STRVAR(token_enter__doc__,
210
"__enter__($self, /)\n"
211
"--\n"
212
"\n"
213
"Enter into Token context manager.");
214
215
#define TOKEN_ENTER_METHODDEF    \
216
    {"__enter__", (PyCFunction)token_enter, METH_NOARGS, token_enter__doc__},
217
218
static PyObject *
219
token_enter_impl(PyContextToken *self);
220
221
static PyObject *
222
token_enter(PyObject *self, PyObject *Py_UNUSED(ignored))
223
0
{
224
0
    return token_enter_impl((PyContextToken *)self);
225
0
}
226
227
PyDoc_STRVAR(token_exit__doc__,
228
"__exit__($self, type, val, tb, /)\n"
229
"--\n"
230
"\n"
231
"Exit from Token context manager, restore the linked ContextVar.");
232
233
#define TOKEN_EXIT_METHODDEF    \
234
    {"__exit__", _PyCFunction_CAST(token_exit), METH_FASTCALL, token_exit__doc__},
235
236
static PyObject *
237
token_exit_impl(PyContextToken *self, PyObject *type, PyObject *val,
238
                PyObject *tb);
239
240
static PyObject *
241
token_exit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
242
0
{
243
0
    PyObject *return_value = NULL;
244
0
    PyObject *type;
245
0
    PyObject *val;
246
0
    PyObject *tb;
247
248
0
    if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
249
0
        goto exit;
250
0
    }
251
0
    type = args[0];
252
0
    val = args[1];
253
0
    tb = args[2];
254
0
    return_value = token_exit_impl((PyContextToken *)self, type, val, tb);
255
256
0
exit:
257
0
    return return_value;
258
0
}
259
/*[clinic end generated code: output=3a04b2fddf24c3e9 input=a9049054013a1b77]*/