cpython/Objects/genericaliasobject.c

// types.GenericAlias -- used to represent e.g. list[int].

#include "Python.h"
#include "pycore_ceval.h"         // _PyEval_GetBuiltin()
#include "pycore_modsupport.h"    // _PyArg_NoKeywords()
#include "pycore_object.h"
#include "pycore_typevarobject.h" // _Py_typing_type_repr
#include "pycore_unionobject.h"   // _Py_union_type_or, _PyGenericAlias_Check


#include <stdbool.h>

gaobject;

gaiterobject;

static void
ga_dealloc(PyObject *self)
{}

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

static int
ga_repr_items_list(PyUnicodeWriter *writer, PyObject *p)
{}

static PyObject *
ga_repr(PyObject *self)
{}

// Index of item in self[:len], or -1 if not found (self is a tuple)
static Py_ssize_t
tuple_index(PyObject *self, Py_ssize_t len, PyObject *item)
{}

static int
tuple_add(PyObject *self, Py_ssize_t len, PyObject *item)
{}

static Py_ssize_t
tuple_extend(PyObject **dst, Py_ssize_t dstindex,
             PyObject **src, Py_ssize_t count)
{}

PyObject *
_Py_make_parameters(PyObject *args)
{}

/* If obj is a generic alias, substitute type variables params
   with substitutions argitems.  For example, if obj is list[T],
   params is (T, S), and argitems is (str, int), return list[str].
   If obj doesn't have a __parameters__ attribute or that's not
   a non-empty tuple, return a new reference to obj. */
static PyObject *
subs_tvars(PyObject *obj, PyObject *params,
           PyObject **argitems, Py_ssize_t nargs)
{}

static int
_is_unpacked_typevartuple(PyObject *arg)
{}

static PyObject *
_unpacked_tuple_args(PyObject *arg)
{}

static PyObject *
_unpack_args(PyObject *item)
{}

PyObject *
_Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObject *item)
{}

PyDoc_STRVAR(genericalias__doc__,
"GenericAlias(origin, args, /)\n"
"--\n\n"
"Represent a PEP 585 generic type\n"
"\n"
"E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).");

static PyObject *
ga_getitem(PyObject *self, PyObject *item)
{}

static PyMappingMethods ga_as_mapping =;

static Py_hash_t
ga_hash(PyObject *self)
{}

static inline PyObject *
set_orig_class(PyObject *obj, PyObject *self)
{}

static PyObject *
ga_call(PyObject *self, PyObject *args, PyObject *kwds)
{}

static PyObject *
ga_vectorcall(PyObject *self, PyObject *const *args,
              size_t nargsf, PyObject *kwnames)
{}

static const char* const attr_exceptions[] =;

static PyObject *
ga_getattro(PyObject *self, PyObject *name)
{}

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

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

static PyObject *
ga_instancecheck(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject *
ga_subclasscheck(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject *
ga_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject *
ga_dir(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyMethodDef ga_methods[] =;

static PyMemberDef ga_members[] =;

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

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

static PyGetSetDef ga_properties[] =;

/* A helper function to create GenericAlias' args tuple and set its attributes.
 * Returns 1 on success, 0 on failure.
 */
static inline int
setup_ga(gaobject *alias, PyObject *origin, PyObject *args) {}

static PyObject *
ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{}

static PyNumberMethods ga_as_number =;

static PyObject *
ga_iternext(gaiterobject *gi) {}

static void
ga_iter_dealloc(gaiterobject *gi) {}

static int
ga_iter_traverse(gaiterobject *gi, visitproc visit, void *arg)
{}

static int
ga_iter_clear(PyObject *self) {}

static PyObject *
ga_iter_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyMethodDef ga_iter_methods[] =;

// gh-91632: _Py_GenericAliasIterType is exported  to be cleared
// in _PyTypes_FiniTypes.
PyTypeObject _Py_GenericAliasIterType =;

static PyObject *
ga_iter(PyObject *self) {}

// TODO:
// - argument clinic?
// - cache?
PyTypeObject Py_GenericAliasType =;

PyObject *
Py_GenericAlias(PyObject *origin, PyObject *args)
{}