cpython/Objects/typevarobject.c

// TypeVar, TypeVarTuple, and ParamSpec
#include "Python.h"
#include "pycore_object.h"        // _PyObject_GC_TRACK/UNTRACK
#include "pycore_typevarobject.h"
#include "pycore_unionobject.h"   // _Py_union_type_or


/*[clinic input]
class typevar "typevarobject *" "&_PyTypeVar_Type"
class paramspec "paramspecobject *" "&_PyParamSpec_Type"
class paramspecargs "paramspecattrobject *" "&_PyParamSpecArgs_Type"
class paramspeckwargs "paramspecattrobject *" "&_PyParamSpecKwargs_Type"
class typevartuple "typevartupleobject *" "&_PyTypeVarTuple_Type"
class typealias "typealiasobject *" "&_PyTypeAlias_Type"
class Generic "PyObject *" "&PyGeneric_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=aa86741931a0f55c]*/

typevarobject;

typevartupleobject;

paramspecobject;

typealiasobject;

#include "clinic/typevarobject.c.h"

/* NoDefault is a marker object to indicate that a parameter has no default. */

static PyObject *
NoDefault_repr(PyObject *op)
{}

static PyObject *
NoDefault_reduce(PyObject *op, PyObject *Py_UNUSED(ignored))
{}

static PyMethodDef nodefault_methods[] =;

static PyObject *
nodefault_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{}

static void
nodefault_dealloc(PyObject *nodefault)
{}

PyDoc_STRVAR(nodefault_doc,
"NoDefaultType()\n"
"--\n\n"
"The type of the NoDefault singleton.");

PyTypeObject _PyNoDefault_Type =;

PyObject _Py_NoDefaultStruct =;

constevaluatorobject;

static void
constevaluator_dealloc(PyObject *self)
{}

static int
constevaluator_traverse(PyObject *self, visitproc visit, void *arg)
{}

static int
constevaluator_clear(PyObject *self)
{}

static PyObject *
constevaluator_repr(PyObject *self)
{}

static PyObject *
constevaluator_call(PyObject *self, PyObject *args, PyObject *kwargs)
{}

static PyObject *
constevaluator_alloc(PyObject *value)
{}

PyDoc_STRVAR(constevaluator_doc,
"_ConstEvaluator()\n"
"--\n\n"
"Internal type for implementing evaluation functions.");

static PyType_Slot constevaluator_slots[] =;

PyType_Spec constevaluator_spec =;

int
_Py_typing_type_repr(PyUnicodeWriter *writer, PyObject *p)
{}


static PyObject *
call_typing_func_object(const char *name, PyObject **args, size_t nargs)
{}

static PyObject *
type_check(PyObject *arg, const char *msg)
{}

/*
 * Return a typing.Union. This is used as the nb_or (|) operator for
 * TypeVar and ParamSpec. We use this rather than _Py_union_type_or
 * (which would produce a types.Union) because historically TypeVar
 * supported unions with string forward references, and we want to
 * preserve that behavior. _Py_union_type_or only allows a small set
 * of types.
 */
static PyObject *
make_union(PyObject *self, PyObject *other)
{}

static PyObject *
caller(void)
{}

static PyObject *
typevartuple_unpack(PyObject *tvt)
{}

static int
contains_typevartuple(PyTupleObject *params)
{}

static PyObject *
unpack_typevartuples(PyObject *params)
{}

static void
typevar_dealloc(PyObject *self)
{}

static int
typevar_traverse(PyObject *self, visitproc visit, void *arg)
{}

static int
typevar_clear(typevarobject *self)
{}

static PyObject *
typevar_repr(PyObject *self)
{}

static PyMemberDef typevar_members[] =;

static PyObject *
typevar_bound(typevarobject *self, void *Py_UNUSED(ignored))
{}

static PyObject *
typevar_default(typevarobject *self, void *unused)
{}

static PyObject *
typevar_constraints(typevarobject *self, void *Py_UNUSED(ignored))
{}

static PyObject *
typevar_evaluate_bound(typevarobject *self, void *Py_UNUSED(ignored))
{}

static PyObject *
typevar_evaluate_constraints(typevarobject *self, void *Py_UNUSED(ignored))
{}

static PyObject *
typevar_evaluate_default(typevarobject *self, void *Py_UNUSED(ignored))
{}

static PyGetSetDef typevar_getset[] =;

static typevarobject *
typevar_alloc(PyObject *name, PyObject *bound, PyObject *evaluate_bound,
              PyObject *constraints, PyObject *evaluate_constraints,
              PyObject *default_value,
              bool covariant, bool contravariant, bool infer_variance,
              PyObject *module)
{}

/*[clinic input]
@classmethod
typevar.__new__ as typevar_new

    name: object(subclass_of="&PyUnicode_Type")
    *constraints: object
    bound: object = None
    default as default_value: object(c_default="&_Py_NoDefaultStruct") = typing.NoDefault
    covariant: bool = False
    contravariant: bool = False
    infer_variance: bool = False

Create a TypeVar.
[clinic start generated code]*/

static PyObject *
typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints,
                 PyObject *bound, PyObject *default_value, int covariant,
                 int contravariant, int infer_variance)
/*[clinic end generated code: output=d2b248ff074eaab6 input=836f97f631d7293a]*/
{}

/*[clinic input]
typevar.__typing_subst__ as typevar_typing_subst

    arg: object
    /

[clinic start generated code]*/

static PyObject *
typevar_typing_subst(typevarobject *self, PyObject *arg)
/*[clinic end generated code: output=0773735e8ce18968 input=9e87b57f0fc59b92]*/
{}

/*[clinic input]
typevar.__typing_prepare_subst__ as typevar_typing_prepare_subst

    alias: object
    args: object
    /

[clinic start generated code]*/

static PyObject *
typevar_typing_prepare_subst_impl(typevarobject *self, PyObject *alias,
                                  PyObject *args)
/*[clinic end generated code: output=82c3f4691e0ded22 input=201a750415d14ffb]*/
{}

/*[clinic input]
typevar.__reduce__ as typevar_reduce

[clinic start generated code]*/

static PyObject *
typevar_reduce_impl(typevarobject *self)
/*[clinic end generated code: output=02e5c55d7cf8a08f input=de76bc95f04fb9ff]*/
{}


/*[clinic input]
typevar.has_default as typevar_has_default

[clinic start generated code]*/

static PyObject *
typevar_has_default_impl(typevarobject *self)
/*[clinic end generated code: output=76bf0b8dc98b97dd input=31024aa030761cf6]*/
{}

static PyObject *
typevar_mro_entries(PyObject *self, PyObject *args)
{}

static PyMethodDef typevar_methods[] =;

PyDoc_STRVAR(typevar_doc,
"Type variable.\n\
\n\
The preferred way to construct a type variable is via the dedicated\n\
syntax for generic functions, classes, and type aliases::\n\
\n\
    class Sequence[T]:  # T is a TypeVar\n\
        ...\n\
\n\
This syntax can also be used to create bound and constrained type\n\
variables::\n\
\n\
    # S is a TypeVar bound to str\n\
    class StrSequence[S: str]:\n\
        ...\n\
\n\
    # A is a TypeVar constrained to str or bytes\n\
    class StrOrBytesSequence[A: (str, bytes)]:\n\
        ...\n\
\n\
Type variables can also have defaults:\n\
\n\
    class IntDefault[T = int]:\n\
        ...\n\
\n\
However, if desired, reusable type variables can also be constructed\n\
manually, like so::\n\
\n\
   T = TypeVar('T')  # Can be anything\n\
   S = TypeVar('S', bound=str)  # Can be any subtype of str\n\
   A = TypeVar('A', str, bytes)  # Must be exactly str or bytes\n\
   D = TypeVar('D', default=int)  # Defaults to int\n\
\n\
Type variables exist primarily for the benefit of static type\n\
checkers.  They serve as the parameters for generic types as well\n\
as for generic function and type alias definitions.\n\
\n\
The variance of type variables is inferred by type checkers when they\n\
are created through the type parameter syntax and when\n\
``infer_variance=True`` is passed. Manually created type variables may\n\
be explicitly marked covariant or contravariant by passing\n\
``covariant=True`` or ``contravariant=True``. By default, manually\n\
created type variables are invariant. See PEP 484 and PEP 695 for more\n\
details.\n\
");

static PyType_Slot typevar_slots[] =;

PyType_Spec typevar_spec =;

paramspecattrobject;

static void
paramspecattr_dealloc(PyObject *self)
{}

static int
paramspecattr_traverse(PyObject *self, visitproc visit, void *arg)
{}

static int
paramspecattr_clear(paramspecattrobject *self)
{}

static PyObject *
paramspecattr_richcompare(PyObject *a, PyObject *b, int op)
{}

static PyMemberDef paramspecattr_members[] =;

static paramspecattrobject *
paramspecattr_new(PyTypeObject *tp, PyObject *origin)
{}

static PyObject *
paramspecargs_repr(PyObject *self)
{}


/*[clinic input]
@classmethod
paramspecargs.__new__ as paramspecargs_new

    origin: object

Create a ParamSpecArgs object.
[clinic start generated code]*/

static PyObject *
paramspecargs_new_impl(PyTypeObject *type, PyObject *origin)
/*[clinic end generated code: output=9a1463dc8942fe4e input=3596a0bb6183c208]*/
{}

static PyObject *
paramspecargs_mro_entries(PyObject *self, PyObject *args)
{}

static PyMethodDef paramspecargs_methods[] =;

PyDoc_STRVAR(paramspecargs_doc,
"The args for a ParamSpec object.\n\
\n\
Given a ParamSpec object P, P.args is an instance of ParamSpecArgs.\n\
\n\
ParamSpecArgs objects have a reference back to their ParamSpec::\n\
\n\
    >>> P = ParamSpec(\"P\")\n\
    >>> P.args.__origin__ is P\n\
    True\n\
\n\
This type is meant for runtime introspection and has no special meaning\n\
to static type checkers.\n\
");

static PyType_Slot paramspecargs_slots[] =;

PyType_Spec paramspecargs_spec =;

static PyObject *
paramspeckwargs_repr(PyObject *self)
{}

/*[clinic input]
@classmethod
paramspeckwargs.__new__ as paramspeckwargs_new

    origin: object

Create a ParamSpecKwargs object.
[clinic start generated code]*/

static PyObject *
paramspeckwargs_new_impl(PyTypeObject *type, PyObject *origin)
/*[clinic end generated code: output=277b11967ebaf4ab input=981bca9b0cf9e40a]*/
{}

static PyObject *
paramspeckwargs_mro_entries(PyObject *self, PyObject *args)
{}

static PyMethodDef paramspeckwargs_methods[] =;

PyDoc_STRVAR(paramspeckwargs_doc,
"The kwargs for a ParamSpec object.\n\
\n\
Given a ParamSpec object P, P.kwargs is an instance of ParamSpecKwargs.\n\
\n\
ParamSpecKwargs objects have a reference back to their ParamSpec::\n\
\n\
    >>> P = ParamSpec(\"P\")\n\
    >>> P.kwargs.__origin__ is P\n\
    True\n\
\n\
This type is meant for runtime introspection and has no special meaning\n\
to static type checkers.\n\
");

static PyType_Slot paramspeckwargs_slots[] =;

PyType_Spec paramspeckwargs_spec =;

static void
paramspec_dealloc(PyObject *self)
{}

static int
paramspec_traverse(PyObject *self, visitproc visit, void *arg)
{}

static int
paramspec_clear(paramspecobject *self)
{}

static PyObject *
paramspec_repr(PyObject *self)
{}

static PyMemberDef paramspec_members[] =;

static PyObject *
paramspec_args(PyObject *self, void *unused)
{}

static PyObject *
paramspec_kwargs(PyObject *self, void *unused)
{}

static PyObject *
paramspec_default(paramspecobject *self, void *unused)
{}

static PyObject *
paramspec_evaluate_default(paramspecobject *self, void *unused)
{}

static PyGetSetDef paramspec_getset[] =;

static paramspecobject *
paramspec_alloc(PyObject *name, PyObject *bound, PyObject *default_value, bool covariant,
                bool contravariant, bool infer_variance, PyObject *module)
{}

/*[clinic input]
@classmethod
paramspec.__new__ as paramspec_new

    name: object(subclass_of="&PyUnicode_Type")
    *
    bound: object = None
    default as default_value: object(c_default="&_Py_NoDefaultStruct") = typing.NoDefault
    covariant: bool = False
    contravariant: bool = False
    infer_variance: bool = False

Create a ParamSpec object.
[clinic start generated code]*/

static PyObject *
paramspec_new_impl(PyTypeObject *type, PyObject *name, PyObject *bound,
                   PyObject *default_value, int covariant, int contravariant,
                   int infer_variance)
/*[clinic end generated code: output=47ca9d63fa5a094d input=495e1565bc067ab9]*/
{}


/*[clinic input]
paramspec.__typing_subst__ as paramspec_typing_subst

    arg: object
    /

[clinic start generated code]*/

static PyObject *
paramspec_typing_subst(paramspecobject *self, PyObject *arg)
/*[clinic end generated code: output=4c5b4aaada1c5814 input=2d5b5e3d4a717189]*/
{}

/*[clinic input]
paramspec.__typing_prepare_subst__ as paramspec_typing_prepare_subst

    alias: object
    args: object
    /

[clinic start generated code]*/

static PyObject *
paramspec_typing_prepare_subst_impl(paramspecobject *self, PyObject *alias,
                                    PyObject *args)
/*[clinic end generated code: output=95449d630a2adb9a input=6df6f9fef3e150da]*/
{}

/*[clinic input]
paramspec.__reduce__ as paramspec_reduce

[clinic start generated code]*/

static PyObject *
paramspec_reduce_impl(paramspecobject *self)
/*[clinic end generated code: output=b83398674416db27 input=5bf349f0d5dd426c]*/
{}

/*[clinic input]
paramspec.has_default as paramspec_has_default

[clinic start generated code]*/

static PyObject *
paramspec_has_default_impl(paramspecobject *self)
/*[clinic end generated code: output=daaae7467a6a4368 input=2112e97eeb76cd59]*/
{}

static PyObject *
paramspec_mro_entries(PyObject *self, PyObject *args)
{}

static PyMethodDef paramspec_methods[] =;

PyDoc_STRVAR(paramspec_doc,
"Parameter specification variable.\n\
\n\
The preferred way to construct a parameter specification is via the\n\
dedicated syntax for generic functions, classes, and type aliases,\n\
where the use of '**' creates a parameter specification::\n\
\n\
    type IntFunc[**P] = Callable[P, int]\n\
\n\
The following syntax creates a parameter specification that defaults\n\
to a callable accepting two positional-only arguments of types int\n\
and str:\n\
\n\
    type IntFuncDefault[**P = (int, str)] = Callable[P, int]\n\
\n\
For compatibility with Python 3.11 and earlier, ParamSpec objects\n\
can also be created as follows::\n\
\n\
    P = ParamSpec('P')\n\
    DefaultP = ParamSpec('DefaultP', default=(int, str))\n\
\n\
Parameter specification variables exist primarily for the benefit of\n\
static type checkers.  They are used to forward the parameter types of\n\
one callable to another callable, a pattern commonly found in\n\
higher-order functions and decorators.  They are only valid when used\n\
in ``Concatenate``, or as the first argument to ``Callable``, or as\n\
parameters for user-defined Generics. See class Generic for more\n\
information on generic types.\n\
\n\
An example for annotating a decorator::\n\
\n\
    def add_logging[**P, T](f: Callable[P, T]) -> Callable[P, T]:\n\
        '''A type-safe decorator to add logging to a function.'''\n\
        def inner(*args: P.args, **kwargs: P.kwargs) -> T:\n\
            logging.info(f'{f.__name__} was called')\n\
            return f(*args, **kwargs)\n\
        return inner\n\
\n\
    @add_logging\n\
    def add_two(x: float, y: float) -> float:\n\
        '''Add two numbers together.'''\n\
        return x + y\n\
\n\
Parameter specification variables can be introspected. e.g.::\n\
\n\
    >>> P = ParamSpec(\"P\")\n\
    >>> P.__name__\n\
    'P'\n\
\n\
Note that only parameter specification variables defined in the global\n\
scope can be pickled.\n\
");

static PyType_Slot paramspec_slots[] =;

PyType_Spec paramspec_spec =;

static void
typevartuple_dealloc(PyObject *self)
{}

static PyObject *
typevartuple_iter(PyObject *self)
{}

static PyObject *
typevartuple_repr(PyObject *self)
{}

static PyMemberDef typevartuple_members[] =;

static typevartupleobject *
typevartuple_alloc(PyObject *name, PyObject *module, PyObject *default_value)
{}

/*[clinic input]
@classmethod
typevartuple.__new__

    name: object(subclass_of="&PyUnicode_Type")
    *
    default as default_value: object(c_default="&_Py_NoDefaultStruct") = typing.NoDefault

Create a new TypeVarTuple with the given name.
[clinic start generated code]*/

static PyObject *
typevartuple_impl(PyTypeObject *type, PyObject *name,
                  PyObject *default_value)
/*[clinic end generated code: output=9d6b76dfe95aae51 input=e149739929a866d0]*/
{}

/*[clinic input]
typevartuple.__typing_subst__ as typevartuple_typing_subst

    arg: object
    /

[clinic start generated code]*/

static PyObject *
typevartuple_typing_subst(typevartupleobject *self, PyObject *arg)
/*[clinic end generated code: output=237054c6d7484eea input=3fcf2dfd9eee7945]*/
{}

/*[clinic input]
typevartuple.__typing_prepare_subst__ as typevartuple_typing_prepare_subst

    alias: object
    args: object
    /

[clinic start generated code]*/

static PyObject *
typevartuple_typing_prepare_subst_impl(typevartupleobject *self,
                                       PyObject *alias, PyObject *args)
/*[clinic end generated code: output=ff999bc5b02036c1 input=685b149b0fc47556]*/
{}

/*[clinic input]
typevartuple.__reduce__ as typevartuple_reduce

[clinic start generated code]*/

static PyObject *
typevartuple_reduce_impl(typevartupleobject *self)
/*[clinic end generated code: output=3215bc0477913d20 input=3018a4d66147e807]*/
{}


/*[clinic input]
typevartuple.has_default as typevartuple_has_default

[clinic start generated code]*/

static PyObject *
typevartuple_has_default_impl(typevartupleobject *self)
/*[clinic end generated code: output=4895f602f56a5e29 input=9ef3250ddb2c1851]*/
{}

static PyObject *
typevartuple_mro_entries(PyObject *self, PyObject *args)
{}

static int
typevartuple_traverse(PyObject *self, visitproc visit, void *arg)
{}

static int
typevartuple_clear(PyObject *self)
{}

static PyObject *
typevartuple_default(typevartupleobject *self, void *unused)
{}

static PyObject *
typevartuple_evaluate_default(typevartupleobject *self, void *unused)
{}

static PyGetSetDef typevartuple_getset[] =;

static PyMethodDef typevartuple_methods[] =;

PyDoc_STRVAR(typevartuple_doc,
"Type variable tuple. A specialized form of type variable that enables\n\
variadic generics.\n\
\n\
The preferred way to construct a type variable tuple is via the\n\
dedicated syntax for generic functions, classes, and type aliases,\n\
where a single '*' indicates a type variable tuple::\n\
\n\
    def move_first_element_to_last[T, *Ts](tup: tuple[T, *Ts]) -> tuple[*Ts, T]:\n\
        return (*tup[1:], tup[0])\n\
\n\
Type variables tuples can have default values:\n\
\n\
    type AliasWithDefault[*Ts = (str, int)] = tuple[*Ts]\n\
\n\
For compatibility with Python 3.11 and earlier, TypeVarTuple objects\n\
can also be created as follows::\n\
\n\
    Ts = TypeVarTuple('Ts')  # Can be given any name\n\
    DefaultTs = TypeVarTuple('Ts', default=(str, int))\n\
\n\
Just as a TypeVar (type variable) is a placeholder for a single type,\n\
a TypeVarTuple is a placeholder for an *arbitrary* number of types. For\n\
example, if we define a generic class using a TypeVarTuple::\n\
\n\
    class C[*Ts]: ...\n\
\n\
Then we can parameterize that class with an arbitrary number of type\n\
arguments::\n\
\n\
    C[int]       # Fine\n\
    C[int, str]  # Also fine\n\
    C[()]        # Even this is fine\n\
\n\
For more details, see PEP 646.\n\
\n\
Note that only TypeVarTuples defined in the global scope can be\n\
pickled.\n\
");

PyType_Slot typevartuple_slots[] =;

PyType_Spec typevartuple_spec =;

PyObject *
_Py_make_typevar(PyObject *name, PyObject *evaluate_bound, PyObject *evaluate_constraints)
{}

PyObject *
_Py_make_paramspec(PyThreadState *Py_UNUSED(ignored), PyObject *v)
{}

PyObject *
_Py_make_typevartuple(PyThreadState *Py_UNUSED(ignored), PyObject *v)
{}

static PyObject *
get_type_param_default(PyThreadState *ts, PyObject *typeparam) {}

static void
typealias_dealloc(PyObject *self)
{}

static PyObject *
typealias_get_value(typealiasobject *ta)
{}

static PyObject *
typealias_repr(PyObject *self)
{}

static PyMemberDef typealias_members[] =;

static PyObject *
typealias_value(PyObject *self, void *unused)
{}

static PyObject *
typealias_evaluate_value(PyObject *self, void *unused)
{}

static PyObject *
typealias_parameters(PyObject *self, void *unused)
{}

static PyObject *
typealias_type_params(PyObject *self, void *unused)
{}

static PyObject *
typealias_module(PyObject *self, void *unused)
{}

static PyGetSetDef typealias_getset[] =;

static PyObject *
typealias_check_type_params(PyObject *type_params, int *err) {}

static PyObject *
typelias_convert_type_params(PyObject *type_params)
{}

static typealiasobject *
typealias_alloc(PyObject *name, PyObject *type_params, PyObject *compute_value,
                PyObject *value, PyObject *module)
{}

static int
typealias_traverse(typealiasobject *self, visitproc visit, void *arg)
{}

static int
typealias_clear(typealiasobject *self)
{}

/*[clinic input]
typealias.__reduce__ as typealias_reduce

[clinic start generated code]*/

static PyObject *
typealias_reduce_impl(typealiasobject *self)
/*[clinic end generated code: output=913724f92ad3b39b input=4f06fbd9472ec0f1]*/
{}

static PyObject *
typealias_subscript(PyObject *self, PyObject *args)
{}

static PyMethodDef typealias_methods[] =;


/*[clinic input]
@classmethod
typealias.__new__ as typealias_new

    name: object(subclass_of="&PyUnicode_Type")
    value: object
    *
    type_params: object = NULL

Create a TypeAliasType.
[clinic start generated code]*/

static PyObject *
typealias_new_impl(PyTypeObject *type, PyObject *name, PyObject *value,
                   PyObject *type_params)
/*[clinic end generated code: output=8920ce6bdff86f00 input=df163c34e17e1a35]*/
{}

PyDoc_STRVAR(typealias_doc,
"Type alias.\n\
\n\
Type aliases are created through the type statement::\n\
\n\
    type Alias = int\n\
\n\
In this example, Alias and int will be treated equivalently by static\n\
type checkers.\n\
\n\
At runtime, Alias is an instance of TypeAliasType. The __name__\n\
attribute holds the name of the type alias. The value of the type alias\n\
is stored in the __value__ attribute. It is evaluated lazily, so the\n\
value is computed only if the attribute is accessed.\n\
\n\
Type aliases can also be generic::\n\
\n\
    type ListOrSet[T] = list[T] | set[T]\n\
\n\
In this case, the type parameters of the alias are stored in the\n\
__type_params__ attribute.\n\
\n\
See PEP 695 for more information.\n\
");

static PyNumberMethods typealias_as_number =;

static PyMappingMethods typealias_as_mapping =;

PyTypeObject _PyTypeAlias_Type =;

PyObject *
_Py_make_typealias(PyThreadState* unused, PyObject *args)
{}

PyDoc_STRVAR(generic_doc,
"Abstract base class for generic types.\n\
\n\
On Python 3.12 and newer, generic classes implicitly inherit from\n\
Generic when they declare a parameter list after the class's name::\n\
\n\
    class Mapping[KT, VT]:\n\
        def __getitem__(self, key: KT) -> VT:\n\
            ...\n\
        # Etc.\n\
\n\
On older versions of Python, however, generic classes have to\n\
explicitly inherit from Generic.\n\
\n\
After a class has been declared to be generic, it can then be used as\n\
follows::\n\
\n\
    def lookup_name[KT, VT](mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:\n\
        try:\n\
            return mapping[key]\n\
        except KeyError:\n\
            return default\n\
");

PyDoc_STRVAR(generic_class_getitem_doc,
"Parameterizes a generic class.\n\
\n\
At least, parameterizing a generic class is the *main* thing this\n\
method does. For example, for some generic class `Foo`, this is called\n\
when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.\n\
\n\
However, note that this method is also called when defining generic\n\
classes in the first place with `class Foo[T]: ...`.\n\
");

static PyObject *
call_typing_args_kwargs(const char *name, PyTypeObject *cls, PyObject *args, PyObject *kwargs)
{}

static PyObject *
generic_init_subclass(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
{}

static PyObject *
generic_class_getitem(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
{}

PyObject *
_Py_subscript_generic(PyThreadState* unused, PyObject *params)
{}

static PyMethodDef generic_methods[] =;

static void
generic_dealloc(PyObject *self)
{}

static int
generic_traverse(PyObject *self, visitproc visit, void *arg)
{}

static PyType_Slot generic_slots[] =;

PyType_Spec generic_spec =;

int _Py_initialize_generic(PyInterpreterState *interp)
{}

void _Py_clear_generic_types(PyInterpreterState *interp)
{}

PyObject *
_Py_set_typeparam_default(PyThreadState *ts, PyObject *typeparam, PyObject *evaluate_default)
{}