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_UnpackKeywordsWithVararg()
10
11 PyDoc_STRVAR(typevar_new__doc__,
12 "typevar(name, *constraints, bound=None, default=typing.NoDefault,\n"
13 " covariant=False, contravariant=False, infer_variance=False)\n"
14 "--\n"
15 "\n"
16 "Create a TypeVar.");
17
18 static PyObject *
19 typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints,
20 PyObject *bound, PyObject *default_value, int covariant,
21 int contravariant, int infer_variance);
22
23 static PyObject *
typevar_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)24 typevar_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
25 {
26 PyObject *return_value = NULL;
27 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
28
29 #define NUM_KEYWORDS 6
30 static struct {
31 PyGC_Head _this_is_not_used;
32 PyObject_VAR_HEAD
33 PyObject *ob_item[NUM_KEYWORDS];
34 } _kwtuple = {
35 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
36 .ob_item = { &_Py_ID(name), &_Py_ID(bound), &_Py_ID(default), &_Py_ID(covariant), &_Py_ID(contravariant), &_Py_ID(infer_variance), },
37 };
38 #undef NUM_KEYWORDS
39 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
40
41 #else // !Py_BUILD_CORE
42 # define KWTUPLE NULL
43 #endif // !Py_BUILD_CORE
44
45 static const char * const _keywords[] = {"name", "bound", "default", "covariant", "contravariant", "infer_variance", NULL};
46 static _PyArg_Parser _parser = {
47 .keywords = _keywords,
48 .fname = "typevar",
49 .kwtuple = KWTUPLE,
50 };
51 #undef KWTUPLE
52 PyObject *argsbuf[7];
53 PyObject * const *fastargs;
54 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
55 Py_ssize_t noptargs = Py_MIN(nargs, 1) + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
56 PyObject *name;
57 PyObject *constraints = NULL;
58 PyObject *bound = Py_None;
59 PyObject *default_value = &_Py_NoDefaultStruct;
60 int covariant = 0;
61 int contravariant = 0;
62 int infer_variance = 0;
63
64 fastargs = _PyArg_UnpackKeywordsWithVararg(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, 1, argsbuf);
65 if (!fastargs) {
66 goto exit;
67 }
68 if (!PyUnicode_Check(fastargs[0])) {
69 _PyArg_BadArgument("typevar", "argument 'name'", "str", fastargs[0]);
70 goto exit;
71 }
72 name = fastargs[0];
73 constraints = fastargs[1];
74 if (!noptargs) {
75 goto skip_optional_kwonly;
76 }
77 if (fastargs[2]) {
78 bound = fastargs[2];
79 if (!--noptargs) {
80 goto skip_optional_kwonly;
81 }
82 }
83 if (fastargs[3]) {
84 default_value = fastargs[3];
85 if (!--noptargs) {
86 goto skip_optional_kwonly;
87 }
88 }
89 if (fastargs[4]) {
90 covariant = PyObject_IsTrue(fastargs[4]);
91 if (covariant < 0) {
92 goto exit;
93 }
94 if (!--noptargs) {
95 goto skip_optional_kwonly;
96 }
97 }
98 if (fastargs[5]) {
99 contravariant = PyObject_IsTrue(fastargs[5]);
100 if (contravariant < 0) {
101 goto exit;
102 }
103 if (!--noptargs) {
104 goto skip_optional_kwonly;
105 }
106 }
107 infer_variance = PyObject_IsTrue(fastargs[6]);
108 if (infer_variance < 0) {
109 goto exit;
110 }
111 skip_optional_kwonly:
112 return_value = typevar_new_impl(type, name, constraints, bound, default_value, covariant, contravariant, infer_variance);
113
114 exit:
115 Py_XDECREF(constraints);
116 return return_value;
117 }
118
119 PyDoc_STRVAR(typevar_typing_subst__doc__,
120 "__typing_subst__($self, arg, /)\n"
121 "--\n"
122 "\n");
123
124 #define TYPEVAR_TYPING_SUBST_METHODDEF \
125 {"__typing_subst__", (PyCFunction)typevar_typing_subst, METH_O, typevar_typing_subst__doc__},
126
127 PyDoc_STRVAR(typevar_typing_prepare_subst__doc__,
128 "__typing_prepare_subst__($self, alias, args, /)\n"
129 "--\n"
130 "\n");
131
132 #define TYPEVAR_TYPING_PREPARE_SUBST_METHODDEF \
133 {"__typing_prepare_subst__", _PyCFunction_CAST(typevar_typing_prepare_subst), METH_FASTCALL, typevar_typing_prepare_subst__doc__},
134
135 static PyObject *
136 typevar_typing_prepare_subst_impl(typevarobject *self, PyObject *alias,
137 PyObject *args);
138
139 static PyObject *
typevar_typing_prepare_subst(typevarobject * self,PyObject * const * args,Py_ssize_t nargs)140 typevar_typing_prepare_subst(typevarobject *self, PyObject *const *args, Py_ssize_t nargs)
141 {
142 PyObject *return_value = NULL;
143 PyObject *alias;
144 PyObject *__clinic_args;
145
146 if (!_PyArg_CheckPositional("__typing_prepare_subst__", nargs, 2, 2)) {
147 goto exit;
148 }
149 alias = args[0];
150 __clinic_args = args[1];
151 return_value = typevar_typing_prepare_subst_impl(self, alias, __clinic_args);
152
153 exit:
154 return return_value;
155 }
156
157 PyDoc_STRVAR(typevar_reduce__doc__,
158 "__reduce__($self, /)\n"
159 "--\n"
160 "\n");
161
162 #define TYPEVAR_REDUCE_METHODDEF \
163 {"__reduce__", (PyCFunction)typevar_reduce, METH_NOARGS, typevar_reduce__doc__},
164
165 static PyObject *
166 typevar_reduce_impl(typevarobject *self);
167
168 static PyObject *
typevar_reduce(typevarobject * self,PyObject * Py_UNUSED (ignored))169 typevar_reduce(typevarobject *self, PyObject *Py_UNUSED(ignored))
170 {
171 return typevar_reduce_impl(self);
172 }
173
174 PyDoc_STRVAR(typevar_has_default__doc__,
175 "has_default($self, /)\n"
176 "--\n"
177 "\n");
178
179 #define TYPEVAR_HAS_DEFAULT_METHODDEF \
180 {"has_default", (PyCFunction)typevar_has_default, METH_NOARGS, typevar_has_default__doc__},
181
182 static PyObject *
183 typevar_has_default_impl(typevarobject *self);
184
185 static PyObject *
typevar_has_default(typevarobject * self,PyObject * Py_UNUSED (ignored))186 typevar_has_default(typevarobject *self, PyObject *Py_UNUSED(ignored))
187 {
188 return typevar_has_default_impl(self);
189 }
190
191 PyDoc_STRVAR(paramspecargs_new__doc__,
192 "paramspecargs(origin)\n"
193 "--\n"
194 "\n"
195 "Create a ParamSpecArgs object.");
196
197 static PyObject *
198 paramspecargs_new_impl(PyTypeObject *type, PyObject *origin);
199
200 static PyObject *
paramspecargs_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)201 paramspecargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
202 {
203 PyObject *return_value = NULL;
204 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
205
206 #define NUM_KEYWORDS 1
207 static struct {
208 PyGC_Head _this_is_not_used;
209 PyObject_VAR_HEAD
210 PyObject *ob_item[NUM_KEYWORDS];
211 } _kwtuple = {
212 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
213 .ob_item = { &_Py_ID(origin), },
214 };
215 #undef NUM_KEYWORDS
216 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
217
218 #else // !Py_BUILD_CORE
219 # define KWTUPLE NULL
220 #endif // !Py_BUILD_CORE
221
222 static const char * const _keywords[] = {"origin", NULL};
223 static _PyArg_Parser _parser = {
224 .keywords = _keywords,
225 .fname = "paramspecargs",
226 .kwtuple = KWTUPLE,
227 };
228 #undef KWTUPLE
229 PyObject *argsbuf[1];
230 PyObject * const *fastargs;
231 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
232 PyObject *origin;
233
234 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
235 if (!fastargs) {
236 goto exit;
237 }
238 origin = fastargs[0];
239 return_value = paramspecargs_new_impl(type, origin);
240
241 exit:
242 return return_value;
243 }
244
245 PyDoc_STRVAR(paramspeckwargs_new__doc__,
246 "paramspeckwargs(origin)\n"
247 "--\n"
248 "\n"
249 "Create a ParamSpecKwargs object.");
250
251 static PyObject *
252 paramspeckwargs_new_impl(PyTypeObject *type, PyObject *origin);
253
254 static PyObject *
paramspeckwargs_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)255 paramspeckwargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
256 {
257 PyObject *return_value = NULL;
258 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
259
260 #define NUM_KEYWORDS 1
261 static struct {
262 PyGC_Head _this_is_not_used;
263 PyObject_VAR_HEAD
264 PyObject *ob_item[NUM_KEYWORDS];
265 } _kwtuple = {
266 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
267 .ob_item = { &_Py_ID(origin), },
268 };
269 #undef NUM_KEYWORDS
270 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
271
272 #else // !Py_BUILD_CORE
273 # define KWTUPLE NULL
274 #endif // !Py_BUILD_CORE
275
276 static const char * const _keywords[] = {"origin", NULL};
277 static _PyArg_Parser _parser = {
278 .keywords = _keywords,
279 .fname = "paramspeckwargs",
280 .kwtuple = KWTUPLE,
281 };
282 #undef KWTUPLE
283 PyObject *argsbuf[1];
284 PyObject * const *fastargs;
285 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
286 PyObject *origin;
287
288 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
289 if (!fastargs) {
290 goto exit;
291 }
292 origin = fastargs[0];
293 return_value = paramspeckwargs_new_impl(type, origin);
294
295 exit:
296 return return_value;
297 }
298
299 PyDoc_STRVAR(paramspec_new__doc__,
300 "paramspec(name, *, bound=None, default=typing.NoDefault,\n"
301 " covariant=False, contravariant=False, infer_variance=False)\n"
302 "--\n"
303 "\n"
304 "Create a ParamSpec object.");
305
306 static PyObject *
307 paramspec_new_impl(PyTypeObject *type, PyObject *name, PyObject *bound,
308 PyObject *default_value, int covariant, int contravariant,
309 int infer_variance);
310
311 static PyObject *
paramspec_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)312 paramspec_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
313 {
314 PyObject *return_value = NULL;
315 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
316
317 #define NUM_KEYWORDS 6
318 static struct {
319 PyGC_Head _this_is_not_used;
320 PyObject_VAR_HEAD
321 PyObject *ob_item[NUM_KEYWORDS];
322 } _kwtuple = {
323 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
324 .ob_item = { &_Py_ID(name), &_Py_ID(bound), &_Py_ID(default), &_Py_ID(covariant), &_Py_ID(contravariant), &_Py_ID(infer_variance), },
325 };
326 #undef NUM_KEYWORDS
327 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
328
329 #else // !Py_BUILD_CORE
330 # define KWTUPLE NULL
331 #endif // !Py_BUILD_CORE
332
333 static const char * const _keywords[] = {"name", "bound", "default", "covariant", "contravariant", "infer_variance", NULL};
334 static _PyArg_Parser _parser = {
335 .keywords = _keywords,
336 .fname = "paramspec",
337 .kwtuple = KWTUPLE,
338 };
339 #undef KWTUPLE
340 PyObject *argsbuf[6];
341 PyObject * const *fastargs;
342 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
343 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
344 PyObject *name;
345 PyObject *bound = Py_None;
346 PyObject *default_value = &_Py_NoDefaultStruct;
347 int covariant = 0;
348 int contravariant = 0;
349 int infer_variance = 0;
350
351 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
352 if (!fastargs) {
353 goto exit;
354 }
355 if (!PyUnicode_Check(fastargs[0])) {
356 _PyArg_BadArgument("paramspec", "argument 'name'", "str", fastargs[0]);
357 goto exit;
358 }
359 name = fastargs[0];
360 if (!noptargs) {
361 goto skip_optional_kwonly;
362 }
363 if (fastargs[1]) {
364 bound = fastargs[1];
365 if (!--noptargs) {
366 goto skip_optional_kwonly;
367 }
368 }
369 if (fastargs[2]) {
370 default_value = fastargs[2];
371 if (!--noptargs) {
372 goto skip_optional_kwonly;
373 }
374 }
375 if (fastargs[3]) {
376 covariant = PyObject_IsTrue(fastargs[3]);
377 if (covariant < 0) {
378 goto exit;
379 }
380 if (!--noptargs) {
381 goto skip_optional_kwonly;
382 }
383 }
384 if (fastargs[4]) {
385 contravariant = PyObject_IsTrue(fastargs[4]);
386 if (contravariant < 0) {
387 goto exit;
388 }
389 if (!--noptargs) {
390 goto skip_optional_kwonly;
391 }
392 }
393 infer_variance = PyObject_IsTrue(fastargs[5]);
394 if (infer_variance < 0) {
395 goto exit;
396 }
397 skip_optional_kwonly:
398 return_value = paramspec_new_impl(type, name, bound, default_value, covariant, contravariant, infer_variance);
399
400 exit:
401 return return_value;
402 }
403
404 PyDoc_STRVAR(paramspec_typing_subst__doc__,
405 "__typing_subst__($self, arg, /)\n"
406 "--\n"
407 "\n");
408
409 #define PARAMSPEC_TYPING_SUBST_METHODDEF \
410 {"__typing_subst__", (PyCFunction)paramspec_typing_subst, METH_O, paramspec_typing_subst__doc__},
411
412 PyDoc_STRVAR(paramspec_typing_prepare_subst__doc__,
413 "__typing_prepare_subst__($self, alias, args, /)\n"
414 "--\n"
415 "\n");
416
417 #define PARAMSPEC_TYPING_PREPARE_SUBST_METHODDEF \
418 {"__typing_prepare_subst__", _PyCFunction_CAST(paramspec_typing_prepare_subst), METH_FASTCALL, paramspec_typing_prepare_subst__doc__},
419
420 static PyObject *
421 paramspec_typing_prepare_subst_impl(paramspecobject *self, PyObject *alias,
422 PyObject *args);
423
424 static PyObject *
paramspec_typing_prepare_subst(paramspecobject * self,PyObject * const * args,Py_ssize_t nargs)425 paramspec_typing_prepare_subst(paramspecobject *self, PyObject *const *args, Py_ssize_t nargs)
426 {
427 PyObject *return_value = NULL;
428 PyObject *alias;
429 PyObject *__clinic_args;
430
431 if (!_PyArg_CheckPositional("__typing_prepare_subst__", nargs, 2, 2)) {
432 goto exit;
433 }
434 alias = args[0];
435 __clinic_args = args[1];
436 return_value = paramspec_typing_prepare_subst_impl(self, alias, __clinic_args);
437
438 exit:
439 return return_value;
440 }
441
442 PyDoc_STRVAR(paramspec_reduce__doc__,
443 "__reduce__($self, /)\n"
444 "--\n"
445 "\n");
446
447 #define PARAMSPEC_REDUCE_METHODDEF \
448 {"__reduce__", (PyCFunction)paramspec_reduce, METH_NOARGS, paramspec_reduce__doc__},
449
450 static PyObject *
451 paramspec_reduce_impl(paramspecobject *self);
452
453 static PyObject *
paramspec_reduce(paramspecobject * self,PyObject * Py_UNUSED (ignored))454 paramspec_reduce(paramspecobject *self, PyObject *Py_UNUSED(ignored))
455 {
456 return paramspec_reduce_impl(self);
457 }
458
459 PyDoc_STRVAR(paramspec_has_default__doc__,
460 "has_default($self, /)\n"
461 "--\n"
462 "\n");
463
464 #define PARAMSPEC_HAS_DEFAULT_METHODDEF \
465 {"has_default", (PyCFunction)paramspec_has_default, METH_NOARGS, paramspec_has_default__doc__},
466
467 static PyObject *
468 paramspec_has_default_impl(paramspecobject *self);
469
470 static PyObject *
paramspec_has_default(paramspecobject * self,PyObject * Py_UNUSED (ignored))471 paramspec_has_default(paramspecobject *self, PyObject *Py_UNUSED(ignored))
472 {
473 return paramspec_has_default_impl(self);
474 }
475
476 PyDoc_STRVAR(typevartuple__doc__,
477 "typevartuple(name, *, default=typing.NoDefault)\n"
478 "--\n"
479 "\n"
480 "Create a new TypeVarTuple with the given name.");
481
482 static PyObject *
483 typevartuple_impl(PyTypeObject *type, PyObject *name,
484 PyObject *default_value);
485
486 static PyObject *
typevartuple(PyTypeObject * type,PyObject * args,PyObject * kwargs)487 typevartuple(PyTypeObject *type, PyObject *args, PyObject *kwargs)
488 {
489 PyObject *return_value = NULL;
490 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
491
492 #define NUM_KEYWORDS 2
493 static struct {
494 PyGC_Head _this_is_not_used;
495 PyObject_VAR_HEAD
496 PyObject *ob_item[NUM_KEYWORDS];
497 } _kwtuple = {
498 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
499 .ob_item = { &_Py_ID(name), &_Py_ID(default), },
500 };
501 #undef NUM_KEYWORDS
502 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
503
504 #else // !Py_BUILD_CORE
505 # define KWTUPLE NULL
506 #endif // !Py_BUILD_CORE
507
508 static const char * const _keywords[] = {"name", "default", NULL};
509 static _PyArg_Parser _parser = {
510 .keywords = _keywords,
511 .fname = "typevartuple",
512 .kwtuple = KWTUPLE,
513 };
514 #undef KWTUPLE
515 PyObject *argsbuf[2];
516 PyObject * const *fastargs;
517 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
518 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
519 PyObject *name;
520 PyObject *default_value = &_Py_NoDefaultStruct;
521
522 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
523 if (!fastargs) {
524 goto exit;
525 }
526 if (!PyUnicode_Check(fastargs[0])) {
527 _PyArg_BadArgument("typevartuple", "argument 'name'", "str", fastargs[0]);
528 goto exit;
529 }
530 name = fastargs[0];
531 if (!noptargs) {
532 goto skip_optional_kwonly;
533 }
534 default_value = fastargs[1];
535 skip_optional_kwonly:
536 return_value = typevartuple_impl(type, name, default_value);
537
538 exit:
539 return return_value;
540 }
541
542 PyDoc_STRVAR(typevartuple_typing_subst__doc__,
543 "__typing_subst__($self, arg, /)\n"
544 "--\n"
545 "\n");
546
547 #define TYPEVARTUPLE_TYPING_SUBST_METHODDEF \
548 {"__typing_subst__", (PyCFunction)typevartuple_typing_subst, METH_O, typevartuple_typing_subst__doc__},
549
550 PyDoc_STRVAR(typevartuple_typing_prepare_subst__doc__,
551 "__typing_prepare_subst__($self, alias, args, /)\n"
552 "--\n"
553 "\n");
554
555 #define TYPEVARTUPLE_TYPING_PREPARE_SUBST_METHODDEF \
556 {"__typing_prepare_subst__", _PyCFunction_CAST(typevartuple_typing_prepare_subst), METH_FASTCALL, typevartuple_typing_prepare_subst__doc__},
557
558 static PyObject *
559 typevartuple_typing_prepare_subst_impl(typevartupleobject *self,
560 PyObject *alias, PyObject *args);
561
562 static PyObject *
typevartuple_typing_prepare_subst(typevartupleobject * self,PyObject * const * args,Py_ssize_t nargs)563 typevartuple_typing_prepare_subst(typevartupleobject *self, PyObject *const *args, Py_ssize_t nargs)
564 {
565 PyObject *return_value = NULL;
566 PyObject *alias;
567 PyObject *__clinic_args;
568
569 if (!_PyArg_CheckPositional("__typing_prepare_subst__", nargs, 2, 2)) {
570 goto exit;
571 }
572 alias = args[0];
573 __clinic_args = args[1];
574 return_value = typevartuple_typing_prepare_subst_impl(self, alias, __clinic_args);
575
576 exit:
577 return return_value;
578 }
579
580 PyDoc_STRVAR(typevartuple_reduce__doc__,
581 "__reduce__($self, /)\n"
582 "--\n"
583 "\n");
584
585 #define TYPEVARTUPLE_REDUCE_METHODDEF \
586 {"__reduce__", (PyCFunction)typevartuple_reduce, METH_NOARGS, typevartuple_reduce__doc__},
587
588 static PyObject *
589 typevartuple_reduce_impl(typevartupleobject *self);
590
591 static PyObject *
typevartuple_reduce(typevartupleobject * self,PyObject * Py_UNUSED (ignored))592 typevartuple_reduce(typevartupleobject *self, PyObject *Py_UNUSED(ignored))
593 {
594 return typevartuple_reduce_impl(self);
595 }
596
597 PyDoc_STRVAR(typevartuple_has_default__doc__,
598 "has_default($self, /)\n"
599 "--\n"
600 "\n");
601
602 #define TYPEVARTUPLE_HAS_DEFAULT_METHODDEF \
603 {"has_default", (PyCFunction)typevartuple_has_default, METH_NOARGS, typevartuple_has_default__doc__},
604
605 static PyObject *
606 typevartuple_has_default_impl(typevartupleobject *self);
607
608 static PyObject *
typevartuple_has_default(typevartupleobject * self,PyObject * Py_UNUSED (ignored))609 typevartuple_has_default(typevartupleobject *self, PyObject *Py_UNUSED(ignored))
610 {
611 return typevartuple_has_default_impl(self);
612 }
613
614 PyDoc_STRVAR(typealias_reduce__doc__,
615 "__reduce__($self, /)\n"
616 "--\n"
617 "\n");
618
619 #define TYPEALIAS_REDUCE_METHODDEF \
620 {"__reduce__", (PyCFunction)typealias_reduce, METH_NOARGS, typealias_reduce__doc__},
621
622 static PyObject *
623 typealias_reduce_impl(typealiasobject *self);
624
625 static PyObject *
typealias_reduce(typealiasobject * self,PyObject * Py_UNUSED (ignored))626 typealias_reduce(typealiasobject *self, PyObject *Py_UNUSED(ignored))
627 {
628 return typealias_reduce_impl(self);
629 }
630
631 PyDoc_STRVAR(typealias_new__doc__,
632 "typealias(name, value, *, type_params=<unrepresentable>)\n"
633 "--\n"
634 "\n"
635 "Create a TypeAliasType.");
636
637 static PyObject *
638 typealias_new_impl(PyTypeObject *type, PyObject *name, PyObject *value,
639 PyObject *type_params);
640
641 static PyObject *
typealias_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)642 typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
643 {
644 PyObject *return_value = NULL;
645 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
646
647 #define NUM_KEYWORDS 3
648 static struct {
649 PyGC_Head _this_is_not_used;
650 PyObject_VAR_HEAD
651 PyObject *ob_item[NUM_KEYWORDS];
652 } _kwtuple = {
653 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
654 .ob_item = { &_Py_ID(name), &_Py_ID(value), &_Py_ID(type_params), },
655 };
656 #undef NUM_KEYWORDS
657 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
658
659 #else // !Py_BUILD_CORE
660 # define KWTUPLE NULL
661 #endif // !Py_BUILD_CORE
662
663 static const char * const _keywords[] = {"name", "value", "type_params", NULL};
664 static _PyArg_Parser _parser = {
665 .keywords = _keywords,
666 .fname = "typealias",
667 .kwtuple = KWTUPLE,
668 };
669 #undef KWTUPLE
670 PyObject *argsbuf[3];
671 PyObject * const *fastargs;
672 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
673 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
674 PyObject *name;
675 PyObject *value;
676 PyObject *type_params = NULL;
677
678 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 2, 0, argsbuf);
679 if (!fastargs) {
680 goto exit;
681 }
682 if (!PyUnicode_Check(fastargs[0])) {
683 _PyArg_BadArgument("typealias", "argument 'name'", "str", fastargs[0]);
684 goto exit;
685 }
686 name = fastargs[0];
687 value = fastargs[1];
688 if (!noptargs) {
689 goto skip_optional_kwonly;
690 }
691 type_params = fastargs[2];
692 skip_optional_kwonly:
693 return_value = typealias_new_impl(type, name, value, type_params);
694
695 exit:
696 return return_value;
697 }
698 /*[clinic end generated code: output=73b39e550e4e336c input=a9049054013a1b77]*/
699