Coverage Report

Created: 2026-12-01 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Objects/clinic/exceptions.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
#endif
8
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
9
#include "pycore_modsupport.h"    // _PyArg_BadArgument()
10
#include "pycore_runtime.h"       // _Py_SINGLETON()
11
12
static PyObject *
13
BaseException_str_impl(PyBaseExceptionObject *self);
14
15
static PyObject *
16
BaseException_str(PyObject *self)
17
4.99M
{
18
4.99M
    PyObject *return_value = NULL;
19
20
4.99M
    Py_BEGIN_CRITICAL_SECTION(self);
21
4.99M
    return_value = BaseException_str_impl((PyBaseExceptionObject *)self);
22
4.99M
    Py_END_CRITICAL_SECTION();
23
24
4.99M
    return return_value;
25
4.99M
}
26
27
static PyObject *
28
BaseException_repr_impl(PyBaseExceptionObject *self);
29
30
static PyObject *
31
BaseException_repr(PyObject *self)
32
4.90k
{
33
4.90k
    PyObject *return_value = NULL;
34
35
4.90k
    Py_BEGIN_CRITICAL_SECTION(self);
36
4.90k
    return_value = BaseException_repr_impl((PyBaseExceptionObject *)self);
37
4.90k
    Py_END_CRITICAL_SECTION();
38
39
4.90k
    return return_value;
40
4.90k
}
41
42
PyDoc_STRVAR(BaseException___reduce____doc__,
43
"__reduce__($self, /)\n"
44
"--\n"
45
"\n");
46
47
#define BASEEXCEPTION___REDUCE___METHODDEF    \
48
    {"__reduce__", (PyCFunction)BaseException___reduce__, METH_NOARGS, BaseException___reduce____doc__},
49
50
static PyObject *
51
BaseException___reduce___impl(PyBaseExceptionObject *self);
52
53
static PyObject *
54
BaseException___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
55
0
{
56
0
    PyObject *return_value = NULL;
57
58
0
    Py_BEGIN_CRITICAL_SECTION(self);
59
0
    return_value = BaseException___reduce___impl((PyBaseExceptionObject *)self);
60
0
    Py_END_CRITICAL_SECTION();
61
62
0
    return return_value;
63
0
}
64
65
PyDoc_STRVAR(BaseException___setstate____doc__,
66
"__setstate__($self, state, /)\n"
67
"--\n"
68
"\n");
69
70
#define BASEEXCEPTION___SETSTATE___METHODDEF    \
71
    {"__setstate__", (PyCFunction)BaseException___setstate__, METH_O, BaseException___setstate____doc__},
72
73
static PyObject *
74
BaseException___setstate___impl(PyBaseExceptionObject *self, PyObject *state);
75
76
static PyObject *
77
BaseException___setstate__(PyObject *self, PyObject *state)
78
0
{
79
0
    PyObject *return_value = NULL;
80
81
0
    Py_BEGIN_CRITICAL_SECTION(state);
82
0
    return_value = BaseException___setstate___impl((PyBaseExceptionObject *)self, state);
83
0
    Py_END_CRITICAL_SECTION();
84
85
0
    return return_value;
86
0
}
87
88
PyDoc_STRVAR(BaseException_with_traceback__doc__,
89
"with_traceback($self, tb, /)\n"
90
"--\n"
91
"\n"
92
"Set self.__traceback__ to tb and return self.");
93
94
#define BASEEXCEPTION_WITH_TRACEBACK_METHODDEF    \
95
    {"with_traceback", (PyCFunction)BaseException_with_traceback, METH_O, BaseException_with_traceback__doc__},
96
97
static PyObject *
98
BaseException_with_traceback_impl(PyBaseExceptionObject *self, PyObject *tb);
99
100
static PyObject *
101
BaseException_with_traceback(PyObject *self, PyObject *tb)
102
0
{
103
0
    PyObject *return_value = NULL;
104
105
0
    Py_BEGIN_CRITICAL_SECTION(self);
106
0
    return_value = BaseException_with_traceback_impl((PyBaseExceptionObject *)self, tb);
107
0
    Py_END_CRITICAL_SECTION();
108
109
0
    return return_value;
110
0
}
111
112
PyDoc_STRVAR(BaseException_add_note__doc__,
113
"add_note($self, note, /)\n"
114
"--\n"
115
"\n"
116
"Add a note to the exception");
117
118
#define BASEEXCEPTION_ADD_NOTE_METHODDEF    \
119
    {"add_note", (PyCFunction)BaseException_add_note, METH_O, BaseException_add_note__doc__},
120
121
static PyObject *
122
BaseException_add_note_impl(PyBaseExceptionObject *self, PyObject *note);
123
124
static PyObject *
125
BaseException_add_note(PyObject *self, PyObject *arg)
126
53.6k
{
127
53.6k
    PyObject *return_value = NULL;
128
53.6k
    PyObject *note;
129
130
53.6k
    if (!PyUnicode_Check(arg)) {
131
0
        _PyArg_BadArgument("add_note", "argument", "str", arg);
132
0
        goto exit;
133
0
    }
134
53.6k
    note = arg;
135
53.6k
    Py_BEGIN_CRITICAL_SECTION(self);
136
53.6k
    return_value = BaseException_add_note_impl((PyBaseExceptionObject *)self, note);
137
53.6k
    Py_END_CRITICAL_SECTION();
138
139
53.6k
exit:
140
53.6k
    return return_value;
141
53.6k
}
142
143
static PyObject *
144
BaseException_args_get_impl(PyBaseExceptionObject *self);
145
146
static PyObject *
147
BaseException_args_get(PyObject *self, void *Py_UNUSED(context))
148
0
{
149
0
    PyObject *return_value = NULL;
150
151
0
    Py_BEGIN_CRITICAL_SECTION(self);
152
0
    return_value = BaseException_args_get_impl((PyBaseExceptionObject *)self);
153
0
    Py_END_CRITICAL_SECTION();
154
155
0
    return return_value;
156
0
}
157
158
static int
159
BaseException_args_set_impl(PyBaseExceptionObject *self, PyObject *value);
160
161
static int
162
BaseException_args_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context))
163
6.21M
{
164
6.21M
    int return_value = -1;
165
6.21M
    PyObject *value;
166
167
6.21M
    if (arg == NULL) {
168
0
        PyErr_Format(PyExc_AttributeError,
169
0
                     "attribute 'args' of '%.100s' objects cannot be deleted",
170
0
                     Py_TYPE(self)->tp_name);
171
0
        return -1;
172
0
    }
173
6.21M
    value = arg;
174
6.21M
    Py_BEGIN_CRITICAL_SECTION(self);
175
6.21M
    return_value = BaseException_args_set_impl((PyBaseExceptionObject *)self, value);
176
6.21M
    Py_END_CRITICAL_SECTION();
177
178
6.21M
    return return_value;
179
6.21M
}
180
181
static PyObject *
182
BaseException___traceback___get_impl(PyBaseExceptionObject *self);
183
184
static PyObject *
185
BaseException___traceback___get(PyObject *self, void *Py_UNUSED(context))
186
0
{
187
0
    PyObject *return_value = NULL;
188
189
0
    Py_BEGIN_CRITICAL_SECTION(self);
190
0
    return_value = BaseException___traceback___get_impl((PyBaseExceptionObject *)self);
191
0
    Py_END_CRITICAL_SECTION();
192
193
0
    return return_value;
194
0
}
195
196
static int
197
BaseException___traceback___set_impl(PyBaseExceptionObject *self,
198
                                     PyObject *value);
199
200
static int
201
BaseException___traceback___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context))
202
20.6k
{
203
20.6k
    int return_value = -1;
204
20.6k
    PyObject *value;
205
206
20.6k
    if (arg == NULL) {
207
0
        PyErr_Format(PyExc_AttributeError,
208
0
                     "attribute '__traceback__' of '%.100s' objects cannot be deleted",
209
0
                     Py_TYPE(self)->tp_name);
210
0
        return -1;
211
0
    }
212
20.6k
    value = arg;
213
20.6k
    Py_BEGIN_CRITICAL_SECTION(self);
214
20.6k
    return_value = BaseException___traceback___set_impl((PyBaseExceptionObject *)self, value);
215
20.6k
    Py_END_CRITICAL_SECTION();
216
217
20.6k
    return return_value;
218
20.6k
}
219
220
static PyObject *
221
BaseException___context___get_impl(PyBaseExceptionObject *self);
222
223
static PyObject *
224
BaseException___context___get(PyObject *self, void *Py_UNUSED(context))
225
0
{
226
0
    PyObject *return_value = NULL;
227
228
0
    Py_BEGIN_CRITICAL_SECTION(self);
229
0
    return_value = BaseException___context___get_impl((PyBaseExceptionObject *)self);
230
0
    Py_END_CRITICAL_SECTION();
231
232
0
    return return_value;
233
0
}
234
235
static int
236
BaseException___context___set_impl(PyBaseExceptionObject *self,
237
                                   PyObject *value);
238
239
static int
240
BaseException___context___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context))
241
0
{
242
0
    int return_value = -1;
243
0
    PyObject *value;
244
245
0
    if (arg == NULL) {
246
0
        PyErr_Format(PyExc_AttributeError,
247
0
                     "attribute '__context__' of '%.100s' objects cannot be deleted",
248
0
                     Py_TYPE(self)->tp_name);
249
0
        return -1;
250
0
    }
251
0
    value = arg;
252
0
    Py_BEGIN_CRITICAL_SECTION(self);
253
0
    return_value = BaseException___context___set_impl((PyBaseExceptionObject *)self, value);
254
0
    Py_END_CRITICAL_SECTION();
255
256
0
    return return_value;
257
0
}
258
259
static PyObject *
260
BaseException___cause___get_impl(PyBaseExceptionObject *self);
261
262
static PyObject *
263
BaseException___cause___get(PyObject *self, void *Py_UNUSED(context))
264
0
{
265
0
    PyObject *return_value = NULL;
266
267
0
    Py_BEGIN_CRITICAL_SECTION(self);
268
0
    return_value = BaseException___cause___get_impl((PyBaseExceptionObject *)self);
269
0
    Py_END_CRITICAL_SECTION();
270
271
0
    return return_value;
272
0
}
273
274
static int
275
BaseException___cause___set_impl(PyBaseExceptionObject *self,
276
                                 PyObject *value);
277
278
static int
279
BaseException___cause___set(PyObject *self, PyObject *arg, void *Py_UNUSED(context))
280
0
{
281
0
    int return_value = -1;
282
0
    PyObject *value;
283
284
0
    if (arg == NULL) {
285
0
        PyErr_Format(PyExc_AttributeError,
286
0
                     "attribute '__cause__' of '%.100s' objects cannot be deleted",
287
0
                     Py_TYPE(self)->tp_name);
288
0
        return -1;
289
0
    }
290
0
    value = arg;
291
0
    Py_BEGIN_CRITICAL_SECTION(self);
292
0
    return_value = BaseException___cause___set_impl((PyBaseExceptionObject *)self, value);
293
0
    Py_END_CRITICAL_SECTION();
294
295
0
    return return_value;
296
0
}
297
298
PyDoc_STRVAR(BaseExceptionGroup_derive__doc__,
299
"derive($self, excs, /)\n"
300
"--\n"
301
"\n");
302
303
#define BASEEXCEPTIONGROUP_DERIVE_METHODDEF    \
304
    {"derive", (PyCFunction)BaseExceptionGroup_derive, METH_O, BaseExceptionGroup_derive__doc__},
305
306
static PyObject *
307
BaseExceptionGroup_derive_impl(PyBaseExceptionGroupObject *self,
308
                               PyObject *excs);
309
310
static PyObject *
311
BaseExceptionGroup_derive(PyObject *self, PyObject *excs)
312
0
{
313
0
    PyObject *return_value = NULL;
314
315
0
    Py_BEGIN_CRITICAL_SECTION(self);
316
0
    return_value = BaseExceptionGroup_derive_impl((PyBaseExceptionGroupObject *)self, excs);
317
0
    Py_END_CRITICAL_SECTION();
318
319
0
    return return_value;
320
0
}
321
322
PyDoc_STRVAR(BaseExceptionGroup_split__doc__,
323
"split($self, matcher_value, /)\n"
324
"--\n"
325
"\n");
326
327
#define BASEEXCEPTIONGROUP_SPLIT_METHODDEF    \
328
    {"split", (PyCFunction)BaseExceptionGroup_split, METH_O, BaseExceptionGroup_split__doc__},
329
330
static PyObject *
331
BaseExceptionGroup_split_impl(PyBaseExceptionGroupObject *self,
332
                              PyObject *matcher_value);
333
334
static PyObject *
335
BaseExceptionGroup_split(PyObject *self, PyObject *matcher_value)
336
0
{
337
0
    PyObject *return_value = NULL;
338
339
0
    Py_BEGIN_CRITICAL_SECTION(self);
340
0
    return_value = BaseExceptionGroup_split_impl((PyBaseExceptionGroupObject *)self, matcher_value);
341
0
    Py_END_CRITICAL_SECTION();
342
343
0
    return return_value;
344
0
}
345
346
PyDoc_STRVAR(BaseExceptionGroup_subgroup__doc__,
347
"subgroup($self, matcher_value, /)\n"
348
"--\n"
349
"\n");
350
351
#define BASEEXCEPTIONGROUP_SUBGROUP_METHODDEF    \
352
    {"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_O, BaseExceptionGroup_subgroup__doc__},
353
354
static PyObject *
355
BaseExceptionGroup_subgroup_impl(PyBaseExceptionGroupObject *self,
356
                                 PyObject *matcher_value);
357
358
static PyObject *
359
BaseExceptionGroup_subgroup(PyObject *self, PyObject *matcher_value)
360
0
{
361
0
    PyObject *return_value = NULL;
362
363
0
    Py_BEGIN_CRITICAL_SECTION(self);
364
0
    return_value = BaseExceptionGroup_subgroup_impl((PyBaseExceptionGroupObject *)self, matcher_value);
365
0
    Py_END_CRITICAL_SECTION();
366
367
0
    return return_value;
368
0
}
369
370
static int
371
ImportError_init_impl(PyImportErrorObject *self, PyObject *args,
372
                      PyObject *name, PyObject *path, PyObject *name_from);
373
374
static int
375
ImportError_init_helper(PyObject *self, PyObject *const *args,
376
    Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames)
377
2.48k
{
378
2.48k
    int return_value = -1;
379
2.48k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
380
381
2.48k
    #define NUM_KEYWORDS 3
382
2.48k
    static struct {
383
2.48k
        PyGC_Head _this_is_not_used;
384
2.48k
        PyObject_VAR_HEAD
385
2.48k
        Py_hash_t ob_hash;
386
2.48k
        PyObject *ob_item[NUM_KEYWORDS];
387
2.48k
    } _kwtuple = {
388
2.48k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
389
2.48k
        .ob_hash = -1,
390
2.48k
        .ob_item = { &_Py_ID(name), &_Py_ID(path), &_Py_ID(name_from), },
391
2.48k
    };
392
2.48k
    #undef NUM_KEYWORDS
393
2.48k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
394
395
    #else  // !Py_BUILD_CORE
396
    #  define KWTUPLE NULL
397
    #endif  // !Py_BUILD_CORE
398
399
2.48k
    static const char * const _keywords[] = {"name", "path", "name_from", NULL};
400
2.48k
    static _PyArg_Parser _parser = {
401
2.48k
        .keywords = _keywords,
402
2.48k
        .fname = "ImportError",
403
2.48k
        .kwtuple = KWTUPLE,
404
2.48k
    };
405
2.48k
    #undef KWTUPLE
406
2.48k
    PyObject *argsbuf[3];
407
2.48k
    PyObject * const *fastargs;
408
2.48k
    Py_ssize_t noptargs = 0 + nkw - 0;
409
2.48k
    PyObject *__clinic_args = NULL;
410
2.48k
    PyObject *name = NULL;
411
2.48k
    PyObject *path = NULL;
412
2.48k
    PyObject *name_from = NULL;
413
414
2.48k
    fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser,
415
2.48k
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 1, argsbuf);
416
2.48k
    if (!fastargs) {
417
0
        goto exit;
418
0
    }
419
2.48k
    if (!noptargs) {
420
0
        goto skip_optional_kwonly;
421
0
    }
422
2.48k
    if (fastargs[0]) {
423
2.09k
        name = fastargs[0];
424
2.09k
        if (!--noptargs) {
425
1.92k
            goto skip_optional_kwonly;
426
1.92k
        }
427
2.09k
    }
428
560
    if (fastargs[1]) {
429
560
        path = fastargs[1];
430
560
        if (!--noptargs) {
431
526
            goto skip_optional_kwonly;
432
526
        }
433
560
    }
434
34
    name_from = fastargs[2];
435
2.48k
skip_optional_kwonly:
436
2.48k
    __clinic_args = PyTuple_FromArray(args, nargs);
437
2.48k
    if (__clinic_args == NULL) {
438
0
        goto exit;
439
0
    }
440
2.48k
    return_value = ImportError_init_impl((PyImportErrorObject *)self, __clinic_args, name, path, name_from);
441
442
2.48k
exit:
443
    /* Cleanup for args */
444
2.48k
    Py_XDECREF(__clinic_args);
445
446
2.48k
    return return_value;
447
2.48k
}
448
449
static int
450
ImportError_init(PyObject *self, PyObject *args, PyObject *kwargs)
451
354
{
452
354
    return ImportError_init_helper(self, _PyTuple_CAST(args)->ob_item,
453
354
        PyTuple_GET_SIZE(args),
454
354
        kwargs ? PyDict_GET_SIZE(kwargs) : 0,
455
354
        kwargs, NULL);
456
354
}
457
458
static PyObject *
459
ImportError_vectorcall(PyObject *type, PyObject *const *args,
460
    size_t nargsf, PyObject *kwnames)
461
2.13k
{
462
2.13k
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
463
2.13k
    PyObject *self;
464
2.13k
    int _result;
465
466
2.13k
    assert(_PyType_CAST(type)->tp_init == ImportError_init);
467
    /* Make sure the type object is immutable: the generated
468
     * vectorcall doesn't deal e.g. with users reassigning __init__. */
469
2.13k
    assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
470
2.13k
    self = _PyType_CAST(type)->tp_new(_PyType_CAST(type),
471
2.13k
        (PyObject *)&_Py_SINGLETON(tuple_empty), NULL);
472
2.13k
    if (self == NULL) {
473
0
        return NULL;
474
0
    }
475
2.13k
    _result = ImportError_init_helper(self, args, nargs,
476
2.13k
        kwnames ? PyTuple_GET_SIZE(kwnames) : 0,
477
2.13k
        NULL, kwnames);
478
2.13k
    if (_result != 0) {
479
0
        Py_DECREF(self);
480
0
        return NULL;
481
0
    }
482
2.13k
    return self;
483
2.13k
}
484
485
static int
486
NameError_init_impl(PyNameErrorObject *self, PyObject *args, PyObject *name);
487
488
static int
489
NameError_init_helper(PyObject *self, PyObject *const *args,
490
    Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames)
491
5
{
492
5
    int return_value = -1;
493
5
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
494
495
5
    #define NUM_KEYWORDS 1
496
5
    static struct {
497
5
        PyGC_Head _this_is_not_used;
498
5
        PyObject_VAR_HEAD
499
5
        Py_hash_t ob_hash;
500
5
        PyObject *ob_item[NUM_KEYWORDS];
501
5
    } _kwtuple = {
502
5
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
503
5
        .ob_hash = -1,
504
5
        .ob_item = { &_Py_ID(name), },
505
5
    };
506
5
    #undef NUM_KEYWORDS
507
5
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
508
509
    #else  // !Py_BUILD_CORE
510
    #  define KWTUPLE NULL
511
    #endif  // !Py_BUILD_CORE
512
513
5
    static const char * const _keywords[] = {"name", NULL};
514
5
    static _PyArg_Parser _parser = {
515
5
        .keywords = _keywords,
516
5
        .fname = "NameError",
517
5
        .kwtuple = KWTUPLE,
518
5
    };
519
5
    #undef KWTUPLE
520
5
    PyObject *argsbuf[1];
521
5
    PyObject * const *fastargs;
522
5
    Py_ssize_t noptargs = 0 + nkw - 0;
523
5
    PyObject *__clinic_args = NULL;
524
5
    PyObject *name = NULL;
525
526
5
    fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser,
527
5
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 1, argsbuf);
528
5
    if (!fastargs) {
529
0
        goto exit;
530
0
    }
531
5
    if (!noptargs) {
532
5
        goto skip_optional_kwonly;
533
5
    }
534
0
    name = fastargs[0];
535
5
skip_optional_kwonly:
536
5
    __clinic_args = PyTuple_FromArray(args, nargs);
537
5
    if (__clinic_args == NULL) {
538
0
        goto exit;
539
0
    }
540
5
    return_value = NameError_init_impl((PyNameErrorObject *)self, __clinic_args, name);
541
542
5
exit:
543
    /* Cleanup for args */
544
5
    Py_XDECREF(__clinic_args);
545
546
5
    return return_value;
547
5
}
548
549
static int
550
NameError_init(PyObject *self, PyObject *args, PyObject *kwargs)
551
0
{
552
0
    return NameError_init_helper(self, _PyTuple_CAST(args)->ob_item,
553
0
        PyTuple_GET_SIZE(args),
554
0
        kwargs ? PyDict_GET_SIZE(kwargs) : 0,
555
0
        kwargs, NULL);
556
0
}
557
558
static PyObject *
559
NameError_vectorcall(PyObject *type, PyObject *const *args,
560
    size_t nargsf, PyObject *kwnames)
561
5
{
562
5
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
563
5
    PyObject *self;
564
5
    int _result;
565
566
5
    assert(_PyType_CAST(type)->tp_init == NameError_init);
567
    /* Make sure the type object is immutable: the generated
568
     * vectorcall doesn't deal e.g. with users reassigning __init__. */
569
5
    assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
570
5
    self = _PyType_CAST(type)->tp_new(_PyType_CAST(type),
571
5
        (PyObject *)&_Py_SINGLETON(tuple_empty), NULL);
572
5
    if (self == NULL) {
573
0
        return NULL;
574
0
    }
575
5
    _result = NameError_init_helper(self, args, nargs,
576
5
        kwnames ? PyTuple_GET_SIZE(kwnames) : 0,
577
5
        NULL, kwnames);
578
5
    if (_result != 0) {
579
0
        Py_DECREF(self);
580
0
        return NULL;
581
0
    }
582
5
    return self;
583
5
}
584
585
static int
586
AttributeError_init_impl(PyAttributeErrorObject *self, PyObject *args,
587
                         PyObject *name, PyObject *obj);
588
589
static int
590
AttributeError_init_helper(PyObject *self, PyObject *const *args,
591
    Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames)
592
1.35M
{
593
1.35M
    int return_value = -1;
594
1.35M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
595
596
1.35M
    #define NUM_KEYWORDS 2
597
1.35M
    static struct {
598
1.35M
        PyGC_Head _this_is_not_used;
599
1.35M
        PyObject_VAR_HEAD
600
1.35M
        Py_hash_t ob_hash;
601
1.35M
        PyObject *ob_item[NUM_KEYWORDS];
602
1.35M
    } _kwtuple = {
603
1.35M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
604
1.35M
        .ob_hash = -1,
605
1.35M
        .ob_item = { &_Py_ID(name), &_Py_ID(obj), },
606
1.35M
    };
607
1.35M
    #undef NUM_KEYWORDS
608
1.35M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
609
610
    #else  // !Py_BUILD_CORE
611
    #  define KWTUPLE NULL
612
    #endif  // !Py_BUILD_CORE
613
614
1.35M
    static const char * const _keywords[] = {"name", "obj", NULL};
615
1.35M
    static _PyArg_Parser _parser = {
616
1.35M
        .keywords = _keywords,
617
1.35M
        .fname = "AttributeError",
618
1.35M
        .kwtuple = KWTUPLE,
619
1.35M
    };
620
1.35M
    #undef KWTUPLE
621
1.35M
    PyObject *argsbuf[2];
622
1.35M
    PyObject * const *fastargs;
623
1.35M
    Py_ssize_t noptargs = 0 + nkw - 0;
624
1.35M
    PyObject *__clinic_args = NULL;
625
1.35M
    PyObject *name = NULL;
626
1.35M
    PyObject *obj = NULL;
627
628
1.35M
    fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser,
629
1.35M
            /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 1, argsbuf);
630
1.35M
    if (!fastargs) {
631
0
        goto exit;
632
0
    }
633
1.35M
    if (!noptargs) {
634
1.35M
        goto skip_optional_kwonly;
635
1.35M
    }
636
0
    if (fastargs[0]) {
637
0
        name = fastargs[0];
638
0
        if (!--noptargs) {
639
0
            goto skip_optional_kwonly;
640
0
        }
641
0
    }
642
0
    obj = fastargs[1];
643
1.35M
skip_optional_kwonly:
644
1.35M
    __clinic_args = PyTuple_FromArray(args, nargs);
645
1.35M
    if (__clinic_args == NULL) {
646
0
        goto exit;
647
0
    }
648
1.35M
    return_value = AttributeError_init_impl((PyAttributeErrorObject *)self, __clinic_args, name, obj);
649
650
1.35M
exit:
651
    /* Cleanup for args */
652
1.35M
    Py_XDECREF(__clinic_args);
653
654
1.35M
    return return_value;
655
1.35M
}
656
657
static int
658
AttributeError_init(PyObject *self, PyObject *args, PyObject *kwargs)
659
0
{
660
0
    return AttributeError_init_helper(self, _PyTuple_CAST(args)->ob_item,
661
0
        PyTuple_GET_SIZE(args),
662
0
        kwargs ? PyDict_GET_SIZE(kwargs) : 0,
663
0
        kwargs, NULL);
664
0
}
665
666
static PyObject *
667
AttributeError_vectorcall(PyObject *type, PyObject *const *args,
668
    size_t nargsf, PyObject *kwnames)
669
1.35M
{
670
1.35M
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
671
1.35M
    PyObject *self;
672
1.35M
    int _result;
673
674
1.35M
    assert(_PyType_CAST(type)->tp_init == AttributeError_init);
675
    /* Make sure the type object is immutable: the generated
676
     * vectorcall doesn't deal e.g. with users reassigning __init__. */
677
1.35M
    assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
678
1.35M
    self = _PyType_CAST(type)->tp_new(_PyType_CAST(type),
679
1.35M
        (PyObject *)&_Py_SINGLETON(tuple_empty), NULL);
680
1.35M
    if (self == NULL) {
681
0
        return NULL;
682
0
    }
683
1.35M
    _result = AttributeError_init_helper(self, args, nargs,
684
1.35M
        kwnames ? PyTuple_GET_SIZE(kwnames) : 0,
685
1.35M
        NULL, kwnames);
686
1.35M
    if (_result != 0) {
687
0
        Py_DECREF(self);
688
0
        return NULL;
689
0
    }
690
1.35M
    return self;
691
1.35M
}
692
#define BASEEXCEPTION_ARGS_GETSETDEF {"args", (getter)BaseException_args_get, (setter)BaseException_args_set, NULL},
693
694
#define BASEEXCEPTION___TRACEBACK___GETSETDEF {"__traceback__", (getter)BaseException___traceback___get, (setter)BaseException___traceback___set, NULL},
695
696
#define BASEEXCEPTION___CONTEXT___GETSETDEF {"__context__", (getter)BaseException___context___get, (setter)BaseException___context___set, NULL},
697
698
#define BASEEXCEPTION___CAUSE___GETSETDEF {"__cause__", (getter)BaseException___cause___get, (setter)BaseException___cause___set, NULL},
699
700
/*[clinic end generated code: output=c8eaffee13bc041d input=a9049054013a1b77]*/