Coverage Report

Created: 2025-07-04 06:49

/src/cpython/Objects/clinic/funcobject.c.h
Line
Count
Source (jump to first uncovered line)
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
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
11
12
PyDoc_STRVAR(function___annotate____doc__,
13
"Get the code object for a function.");
14
#if defined(function___annotate___DOCSTR)
15
#   undef function___annotate___DOCSTR
16
#endif
17
#define function___annotate___DOCSTR function___annotate____doc__
18
19
#if !defined(function___annotate___DOCSTR)
20
#  define function___annotate___DOCSTR NULL
21
#endif
22
#if defined(FUNCTION___ANNOTATE___GETSETDEF)
23
#  undef FUNCTION___ANNOTATE___GETSETDEF
24
#  define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR},
25
#else
26
#  define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, NULL, function___annotate___DOCSTR},
27
#endif
28
29
static PyObject *
30
function___annotate___get_impl(PyFunctionObject *self);
31
32
static PyObject *
33
function___annotate___get(PyObject *self, void *Py_UNUSED(context))
34
100
{
35
100
    PyObject *return_value = NULL;
36
37
100
    Py_BEGIN_CRITICAL_SECTION(self);
38
100
    return_value = function___annotate___get_impl((PyFunctionObject *)self);
39
100
    Py_END_CRITICAL_SECTION();
40
41
100
    return return_value;
42
100
}
43
44
#if !defined(function___annotate___DOCSTR)
45
#  define function___annotate___DOCSTR NULL
46
#endif
47
#if defined(FUNCTION___ANNOTATE___GETSETDEF)
48
#  undef FUNCTION___ANNOTATE___GETSETDEF
49
#  define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR},
50
#else
51
#  define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", NULL, (setter)function___annotate___set, NULL},
52
#endif
53
54
static int
55
function___annotate___set_impl(PyFunctionObject *self, PyObject *value);
56
57
static int
58
function___annotate___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
59
49
{
60
49
    int return_value;
61
62
49
    Py_BEGIN_CRITICAL_SECTION(self);
63
49
    return_value = function___annotate___set_impl((PyFunctionObject *)self, value);
64
49
    Py_END_CRITICAL_SECTION();
65
66
49
    return return_value;
67
49
}
68
69
PyDoc_STRVAR(function___annotations____doc__,
70
"Dict of annotations in a function object.");
71
#if defined(function___annotations___DOCSTR)
72
#   undef function___annotations___DOCSTR
73
#endif
74
#define function___annotations___DOCSTR function___annotations____doc__
75
76
#if !defined(function___annotations___DOCSTR)
77
#  define function___annotations___DOCSTR NULL
78
#endif
79
#if defined(FUNCTION___ANNOTATIONS___GETSETDEF)
80
#  undef FUNCTION___ANNOTATIONS___GETSETDEF
81
#  define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR},
82
#else
83
#  define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, NULL, function___annotations___DOCSTR},
84
#endif
85
86
static PyObject *
87
function___annotations___get_impl(PyFunctionObject *self);
88
89
static PyObject *
90
function___annotations___get(PyObject *self, void *Py_UNUSED(context))
91
0
{
92
0
    PyObject *return_value = NULL;
93
94
0
    Py_BEGIN_CRITICAL_SECTION(self);
95
0
    return_value = function___annotations___get_impl((PyFunctionObject *)self);
96
0
    Py_END_CRITICAL_SECTION();
97
98
0
    return return_value;
99
0
}
100
101
#if !defined(function___annotations___DOCSTR)
102
#  define function___annotations___DOCSTR NULL
103
#endif
104
#if defined(FUNCTION___ANNOTATIONS___GETSETDEF)
105
#  undef FUNCTION___ANNOTATIONS___GETSETDEF
106
#  define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR},
107
#else
108
#  define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", NULL, (setter)function___annotations___set, NULL},
109
#endif
110
111
static int
112
function___annotations___set_impl(PyFunctionObject *self, PyObject *value);
113
114
static int
115
function___annotations___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
116
0
{
117
0
    int return_value;
118
119
0
    Py_BEGIN_CRITICAL_SECTION(self);
120
0
    return_value = function___annotations___set_impl((PyFunctionObject *)self, value);
121
0
    Py_END_CRITICAL_SECTION();
122
123
0
    return return_value;
124
0
}
125
126
PyDoc_STRVAR(function___type_params____doc__,
127
"Get the declared type parameters for a function.");
128
#if defined(function___type_params___DOCSTR)
129
#   undef function___type_params___DOCSTR
130
#endif
131
#define function___type_params___DOCSTR function___type_params____doc__
132
133
#if !defined(function___type_params___DOCSTR)
134
#  define function___type_params___DOCSTR NULL
135
#endif
136
#if defined(FUNCTION___TYPE_PARAMS___GETSETDEF)
137
#  undef FUNCTION___TYPE_PARAMS___GETSETDEF
138
#  define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR},
139
#else
140
#  define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, NULL, function___type_params___DOCSTR},
141
#endif
142
143
static PyObject *
144
function___type_params___get_impl(PyFunctionObject *self);
145
146
static PyObject *
147
function___type_params___get(PyObject *self, void *Py_UNUSED(context))
148
100
{
149
100
    PyObject *return_value = NULL;
150
151
100
    Py_BEGIN_CRITICAL_SECTION(self);
152
100
    return_value = function___type_params___get_impl((PyFunctionObject *)self);
153
100
    Py_END_CRITICAL_SECTION();
154
155
100
    return return_value;
156
100
}
157
158
#if !defined(function___type_params___DOCSTR)
159
#  define function___type_params___DOCSTR NULL
160
#endif
161
#if defined(FUNCTION___TYPE_PARAMS___GETSETDEF)
162
#  undef FUNCTION___TYPE_PARAMS___GETSETDEF
163
#  define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR},
164
#else
165
#  define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", NULL, (setter)function___type_params___set, NULL},
166
#endif
167
168
static int
169
function___type_params___set_impl(PyFunctionObject *self, PyObject *value);
170
171
static int
172
function___type_params___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
173
49
{
174
49
    int return_value;
175
176
49
    Py_BEGIN_CRITICAL_SECTION(self);
177
49
    return_value = function___type_params___set_impl((PyFunctionObject *)self, value);
178
49
    Py_END_CRITICAL_SECTION();
179
180
49
    return return_value;
181
49
}
182
183
PyDoc_STRVAR(func_new__doc__,
184
"function(code, globals, name=None, argdefs=None, closure=None,\n"
185
"         kwdefaults=None)\n"
186
"--\n"
187
"\n"
188
"Create a function object.\n"
189
"\n"
190
"  code\n"
191
"    a code object\n"
192
"  globals\n"
193
"    the globals dictionary\n"
194
"  name\n"
195
"    a string that overrides the name from the code object\n"
196
"  argdefs\n"
197
"    a tuple that specifies the default argument values\n"
198
"  closure\n"
199
"    a tuple that supplies the bindings for free variables\n"
200
"  kwdefaults\n"
201
"    a dictionary that specifies the default keyword argument values");
202
203
static PyObject *
204
func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
205
              PyObject *name, PyObject *defaults, PyObject *closure,
206
              PyObject *kwdefaults);
207
208
static PyObject *
209
func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
210
0
{
211
0
    PyObject *return_value = NULL;
212
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
213
214
0
    #define NUM_KEYWORDS 6
215
0
    static struct {
216
0
        PyGC_Head _this_is_not_used;
217
0
        PyObject_VAR_HEAD
218
0
        Py_hash_t ob_hash;
219
0
        PyObject *ob_item[NUM_KEYWORDS];
220
0
    } _kwtuple = {
221
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
222
0
        .ob_hash = -1,
223
0
        .ob_item = { &_Py_ID(code), &_Py_ID(globals), &_Py_ID(name), &_Py_ID(argdefs), &_Py_ID(closure), &_Py_ID(kwdefaults), },
224
0
    };
225
0
    #undef NUM_KEYWORDS
226
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
227
228
    #else  // !Py_BUILD_CORE
229
    #  define KWTUPLE NULL
230
    #endif  // !Py_BUILD_CORE
231
232
0
    static const char * const _keywords[] = {"code", "globals", "name", "argdefs", "closure", "kwdefaults", NULL};
233
0
    static _PyArg_Parser _parser = {
234
0
        .keywords = _keywords,
235
0
        .fname = "function",
236
0
        .kwtuple = KWTUPLE,
237
0
    };
238
0
    #undef KWTUPLE
239
0
    PyObject *argsbuf[6];
240
0
    PyObject * const *fastargs;
241
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
242
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
243
0
    PyCodeObject *code;
244
0
    PyObject *globals;
245
0
    PyObject *name = Py_None;
246
0
    PyObject *defaults = Py_None;
247
0
    PyObject *closure = Py_None;
248
0
    PyObject *kwdefaults = Py_None;
249
250
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
251
0
            /*minpos*/ 2, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
252
0
    if (!fastargs) {
253
0
        goto exit;
254
0
    }
255
0
    if (!PyObject_TypeCheck(fastargs[0], &PyCode_Type)) {
256
0
        _PyArg_BadArgument("function", "argument 'code'", (&PyCode_Type)->tp_name, fastargs[0]);
257
0
        goto exit;
258
0
    }
259
0
    code = (PyCodeObject *)fastargs[0];
260
0
    if (!PyDict_Check(fastargs[1])) {
261
0
        _PyArg_BadArgument("function", "argument 'globals'", "dict", fastargs[1]);
262
0
        goto exit;
263
0
    }
264
0
    globals = fastargs[1];
265
0
    if (!noptargs) {
266
0
        goto skip_optional_pos;
267
0
    }
268
0
    if (fastargs[2]) {
269
0
        name = fastargs[2];
270
0
        if (!--noptargs) {
271
0
            goto skip_optional_pos;
272
0
        }
273
0
    }
274
0
    if (fastargs[3]) {
275
0
        defaults = fastargs[3];
276
0
        if (!--noptargs) {
277
0
            goto skip_optional_pos;
278
0
        }
279
0
    }
280
0
    if (fastargs[4]) {
281
0
        closure = fastargs[4];
282
0
        if (!--noptargs) {
283
0
            goto skip_optional_pos;
284
0
        }
285
0
    }
286
0
    kwdefaults = fastargs[5];
287
0
skip_optional_pos:
288
0
    return_value = func_new_impl(type, code, globals, name, defaults, closure, kwdefaults);
289
290
0
exit:
291
0
    return return_value;
292
0
}
293
/*[clinic end generated code: output=12cb900088d41bdb input=a9049054013a1b77]*/