Coverage Report

Created: 2026-12-01 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/clinic/classobject.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
6
7
PyDoc_STRVAR(method___reduce____doc__,
8
"__reduce__($self, /)\n"
9
"--\n"
10
"\n");
11
12
#define METHOD___REDUCE___METHODDEF    \
13
    {"__reduce__", (PyCFunction)method___reduce__, METH_NOARGS, method___reduce____doc__},
14
15
static PyObject *
16
method___reduce___impl(PyMethodObject *self);
17
18
static PyObject *
19
method___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
20
0
{
21
0
    return method___reduce___impl((PyMethodObject *)self);
22
0
}
23
24
PyDoc_STRVAR(method_type_new__doc__,
25
"method(function, instance, /)\n"
26
"--\n"
27
"\n"
28
"Create a bound instance method object.");
29
30
static PyObject *
31
method_type_new_impl(PyTypeObject *type, PyObject *function,
32
                     PyObject *instance);
33
34
static PyObject *
35
method_type_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
36
0
{
37
0
    PyObject *return_value = NULL;
38
0
    PyTypeObject *base_tp = &PyMethod_Type;
39
0
    PyObject *function;
40
0
    PyObject *instance;
41
42
0
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
43
0
        !_PyArg_NoKeywords("method", kwargs)) {
44
0
        goto exit;
45
0
    }
46
0
    if (!_PyArg_CheckPositional("method", PyTuple_GET_SIZE(args), 2, 2)) {
47
0
        goto exit;
48
0
    }
49
0
    function = PyTuple_GET_ITEM(args, 0);
50
0
    instance = PyTuple_GET_ITEM(args, 1);
51
0
    return_value = method_type_new_impl(type, function, instance);
52
53
0
exit:
54
0
    return return_value;
55
0
}
56
57
static PyObject *
58
method_type_vectorcall(PyObject *type, PyObject *const *args,
59
    size_t nargsf, PyObject *kwnames)
60
20
{
61
20
    PyObject *return_value = NULL;
62
20
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
63
20
    PyObject *function;
64
20
    PyObject *instance;
65
66
20
    assert(_PyType_CAST(type)->tp_new == method_type_new);
67
    /* Make sure the type object is immutable: the generated
68
     * vectorcall doesn't deal e.g. with users reassigning __init__. */
69
20
    assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
70
20
    if (!_PyArg_NoKwnames("method", kwnames)) {
71
0
        goto exit;
72
0
    }
73
20
    if (!_PyArg_CheckPositional("method", nargs, 2, 2)) {
74
0
        goto exit;
75
0
    }
76
20
    function = args[0];
77
20
    instance = args[1];
78
20
    return_value = method_type_new_impl(_PyType_CAST(type), function, instance);
79
80
20
exit:
81
20
    return return_value;
82
20
}
83
84
PyDoc_STRVAR(instancemethod_new__doc__,
85
"instancemethod(function, /)\n"
86
"--\n"
87
"\n"
88
"Bind a function to a class.");
89
90
static PyObject *
91
instancemethod_new_impl(PyTypeObject *type, PyObject *function);
92
93
static PyObject *
94
instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
95
0
{
96
0
    PyObject *return_value = NULL;
97
0
    PyTypeObject *base_tp = &PyInstanceMethod_Type;
98
0
    PyObject *function;
99
100
0
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
101
0
        !_PyArg_NoKeywords("instancemethod", kwargs)) {
102
0
        goto exit;
103
0
    }
104
0
    if (!_PyArg_CheckPositional("instancemethod", PyTuple_GET_SIZE(args), 1, 1)) {
105
0
        goto exit;
106
0
    }
107
0
    function = PyTuple_GET_ITEM(args, 0);
108
0
    return_value = instancemethod_new_impl(type, function);
109
110
0
exit:
111
0
    return return_value;
112
0
}
113
/*[clinic end generated code: output=fd5c214ee6e55e88 input=a9049054013a1b77]*/