Coverage Report

Created: 2026-10-31 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/clinic/descrobject.c.h
Line
Count
Source
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_modsupport.h"    // _PyArg_UnpackKeywords()
10
11
PyDoc_STRVAR(mappingproxy_new__doc__,
12
"mappingproxy(mapping)\n"
13
"--\n"
14
"\n"
15
"Read-only proxy of a mapping.");
16
17
static PyObject *
18
mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
19
20
static PyObject *
21
mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
22
983
{
23
983
    PyObject *return_value = NULL;
24
983
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
25
26
983
    #define NUM_KEYWORDS 1
27
983
    static struct {
28
983
        PyGC_Head _this_is_not_used;
29
983
        PyObject_VAR_HEAD
30
983
        Py_hash_t ob_hash;
31
983
        PyObject *ob_item[NUM_KEYWORDS];
32
983
    } _kwtuple = {
33
983
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
34
983
        .ob_hash = -1,
35
983
        .ob_item = { &_Py_ID(mapping), },
36
983
    };
37
983
    #undef NUM_KEYWORDS
38
983
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
39
40
    #else  // !Py_BUILD_CORE
41
    #  define KWTUPLE NULL
42
    #endif  // !Py_BUILD_CORE
43
44
983
    static const char * const _keywords[] = {"mapping", NULL};
45
983
    static _PyArg_Parser _parser = {
46
983
        .keywords = _keywords,
47
983
        .fname = "mappingproxy",
48
983
        .kwtuple = KWTUPLE,
49
983
    };
50
983
    #undef KWTUPLE
51
983
    PyObject *argsbuf[1];
52
983
    PyObject * const *fastargs;
53
983
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
54
983
    PyObject *mapping;
55
56
983
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
57
983
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
58
983
    if (!fastargs) {
59
0
        goto exit;
60
0
    }
61
983
    mapping = fastargs[0];
62
983
    return_value = mappingproxy_new_impl(type, mapping);
63
64
983
exit:
65
983
    return return_value;
66
983
}
67
68
PyDoc_STRVAR(property___set_name____doc__,
69
"__set_name__($self, owner, name, /)\n"
70
"--\n"
71
"\n"
72
"Method to set name of a property.");
73
74
#define PROPERTY___SET_NAME___METHODDEF    \
75
    {"__set_name__", _PyCFunction_CAST(property___set_name__), METH_FASTCALL, property___set_name____doc__},
76
77
static PyObject *
78
property___set_name___impl(propertyobject *self, PyObject *owner,
79
                           PyObject *name);
80
81
static PyObject *
82
property___set_name__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
83
2.66k
{
84
2.66k
    PyObject *return_value = NULL;
85
2.66k
    PyObject *owner;
86
2.66k
    PyObject *name;
87
88
2.66k
    if (!_PyArg_CheckPositional("__set_name__", nargs, 2, 2)) {
89
0
        goto exit;
90
0
    }
91
2.66k
    owner = args[0];
92
2.66k
    name = args[1];
93
2.66k
    return_value = property___set_name___impl((propertyobject *)self, owner, name);
94
95
2.66k
exit:
96
2.66k
    return return_value;
97
2.66k
}
98
99
PyDoc_STRVAR(property_init__doc__,
100
"property(fget=None, fset=None, fdel=None, doc=None)\n"
101
"--\n"
102
"\n"
103
"Property attribute.\n"
104
"\n"
105
"  fget\n"
106
"    function to be used for getting an attribute value\n"
107
"  fset\n"
108
"    function to be used for setting an attribute value\n"
109
"  fdel\n"
110
"    function to be used for del\'ing an attribute\n"
111
"  doc\n"
112
"    docstring\n"
113
"\n"
114
"Typical use is to define a managed attribute x:\n"
115
"\n"
116
"class C(object):\n"
117
"    def getx(self): return self._x\n"
118
"    def setx(self, value): self._x = value\n"
119
"    def delx(self): del self._x\n"
120
"    x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n"
121
"\n"
122
"Decorators make defining new properties or modifying existing ones easy:\n"
123
"\n"
124
"class C(object):\n"
125
"    @property\n"
126
"    def x(self):\n"
127
"        \"I am the \'x\' property.\"\n"
128
"        return self._x\n"
129
"    @x.setter\n"
130
"    def x(self, value):\n"
131
"        self._x = value\n"
132
"    @x.deleter\n"
133
"    def x(self):\n"
134
"        del self._x");
135
136
static int
137
property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
138
                   PyObject *fdel, PyObject *doc);
139
140
static int
141
property_init(PyObject *self, PyObject *args, PyObject *kwargs)
142
2.63k
{
143
2.63k
    int return_value = -1;
144
2.63k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
145
146
2.63k
    #define NUM_KEYWORDS 4
147
2.63k
    static struct {
148
2.63k
        PyGC_Head _this_is_not_used;
149
2.63k
        PyObject_VAR_HEAD
150
2.63k
        Py_hash_t ob_hash;
151
2.63k
        PyObject *ob_item[NUM_KEYWORDS];
152
2.63k
    } _kwtuple = {
153
2.63k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
154
2.63k
        .ob_hash = -1,
155
2.63k
        .ob_item = { &_Py_ID(fget), &_Py_ID(fset), &_Py_ID(fdel), &_Py_ID(doc), },
156
2.63k
    };
157
2.63k
    #undef NUM_KEYWORDS
158
2.63k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
159
160
    #else  // !Py_BUILD_CORE
161
    #  define KWTUPLE NULL
162
    #endif  // !Py_BUILD_CORE
163
164
2.63k
    static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL};
165
2.63k
    static _PyArg_Parser _parser = {
166
2.63k
        .keywords = _keywords,
167
2.63k
        .fname = "property",
168
2.63k
        .kwtuple = KWTUPLE,
169
2.63k
    };
170
2.63k
    #undef KWTUPLE
171
2.63k
    PyObject *argsbuf[4];
172
2.63k
    PyObject * const *fastargs;
173
2.63k
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
174
2.63k
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
175
2.63k
    PyObject *fget = NULL;
176
2.63k
    PyObject *fset = NULL;
177
2.63k
    PyObject *fdel = NULL;
178
2.63k
    PyObject *doc = NULL;
179
180
2.63k
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
181
2.63k
            /*minpos*/ 0, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
182
2.63k
    if (!fastargs) {
183
0
        goto exit;
184
0
    }
185
2.63k
    if (!noptargs) {
186
0
        goto skip_optional_pos;
187
0
    }
188
2.63k
    if (fastargs[0]) {
189
2.63k
        fget = fastargs[0];
190
2.63k
        if (!--noptargs) {
191
2.45k
            goto skip_optional_pos;
192
2.45k
        }
193
2.63k
    }
194
181
    if (fastargs[1]) {
195
181
        fset = fastargs[1];
196
181
        if (!--noptargs) {
197
9
            goto skip_optional_pos;
198
9
        }
199
181
    }
200
172
    if (fastargs[2]) {
201
172
        fdel = fastargs[2];
202
172
        if (!--noptargs) {
203
0
            goto skip_optional_pos;
204
0
        }
205
172
    }
206
172
    doc = fastargs[3];
207
2.63k
skip_optional_pos:
208
2.63k
    return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc);
209
210
2.63k
exit:
211
2.63k
    return return_value;
212
2.63k
}
213
/*[clinic end generated code: output=fb62ee8be13af793 input=a9049054013a1b77]*/