Linux vps-61133.fhnet.fr 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
Apache/2.4.25 (Debian)
Server IP : 93.113.207.21 & Your IP : 216.73.216.35
Domains :
Cant Read [ /etc/named.conf ]
User : www-data
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
usr /
src /
Python-3.10.14 /
Objects /
Delete
Unzip
Name
Size
Permission
Date
Action
clinic
[ DIR ]
drwxr-xr-x
2024-03-19 22:46
stringlib
[ DIR ]
drwxr-xr-x
2024-03-19 22:46
README
41
B
-rw-r--r--
2024-03-19 22:46
abstract.c
78.14
KB
-rw-r--r--
2024-03-19 22:46
abstract.gcda
24.84
KB
-rw-r--r--
2025-06-04 09:21
abstract.o
664.97
KB
-rw-r--r--
2025-06-04 09:22
accu.c
2.41
KB
-rw-r--r--
2024-03-19 22:46
accu.gcda
4.12
KB
-rw-r--r--
2025-06-04 09:21
accu.o
49.66
KB
-rw-r--r--
2025-06-04 09:22
boolobject.c
7.12
KB
-rw-r--r--
2024-03-19 22:46
boolobject.gcda
4.2
KB
-rw-r--r--
2025-06-04 09:21
boolobject.o
51.54
KB
-rw-r--r--
2025-06-04 09:22
bytearrayobject.c
72.53
KB
-rw-r--r--
2024-03-19 22:46
bytearrayobject.gcda
29.45
KB
-rw-r--r--
2025-06-04 09:21
bytearrayobject.o
837.34
KB
-rw-r--r--
2025-06-04 09:22
bytes_methods.c
21.14
KB
-rw-r--r--
2024-03-19 22:46
bytes_methods.gcda
8
KB
-rw-r--r--
2025-06-04 09:21
bytes_methods.o
269.63
KB
-rw-r--r--
2025-06-04 09:22
bytesobject.c
99.98
KB
-rw-r--r--
2024-03-19 22:46
bytesobject.gcda
32.01
KB
-rw-r--r--
2025-06-04 09:21
bytesobject.o
956.34
KB
-rw-r--r--
2025-06-04 09:22
call.c
27.29
KB
-rw-r--r--
2024-03-19 22:46
call.gcda
8.28
KB
-rw-r--r--
2025-06-04 09:21
call.o
339.1
KB
-rw-r--r--
2025-06-04 09:22
capsule.c
7.27
KB
-rw-r--r--
2024-03-19 22:46
capsule.gcda
5.2
KB
-rw-r--r--
2025-06-04 09:21
capsule.o
73.71
KB
-rw-r--r--
2025-06-04 09:22
cellobject.c
5.65
KB
-rw-r--r--
2024-03-19 22:46
cellobject.gcda
4.57
KB
-rw-r--r--
2025-06-04 09:21
cellobject.o
91.55
KB
-rw-r--r--
2025-06-04 09:22
classobject.c
17.99
KB
-rw-r--r--
2024-03-19 22:46
classobject.gcda
7.01
KB
-rw-r--r--
2025-06-04 09:21
classobject.o
149.12
KB
-rw-r--r--
2025-06-04 09:22
codeobject.c
42.38
KB
-rw-r--r--
2024-03-19 22:46
codeobject.gcda
10.02
KB
-rw-r--r--
2025-06-04 09:21
codeobject.o
320.38
KB
-rw-r--r--
2025-06-04 09:22
complexobject.c
30.92
KB
-rw-r--r--
2024-03-19 22:46
complexobject.gcda
8.7
KB
-rw-r--r--
2025-06-04 09:21
complexobject.o
221.24
KB
-rw-r--r--
2025-06-04 09:22
descrobject.c
62.59
KB
-rw-r--r--
2024-03-19 22:46
descrobject.gcda
13.57
KB
-rw-r--r--
2025-06-04 09:21
descrobject.o
441.51
KB
-rw-r--r--
2025-06-04 09:22
dict-common.h
2.22
KB
-rw-r--r--
2024-03-19 22:46
dictnotes.txt
5.96
KB
-rw-r--r--
2024-03-19 22:46
dictobject.c
148.87
KB
-rw-r--r--
2024-03-19 22:46
dictobject.gcda
28.55
KB
-rw-r--r--
2025-06-04 09:21
dictobject.o
1022.94
KB
-rw-r--r--
2025-06-04 09:22
enumobject.c
14.61
KB
-rw-r--r--
2024-03-19 22:46
enumobject.gcda
6.13
KB
-rw-r--r--
2025-06-04 09:21
enumobject.o
140.49
KB
-rw-r--r--
2025-06-04 09:22
exceptions.c
85.65
KB
-rw-r--r--
2024-03-19 22:46
exceptions.gcda
20.98
KB
-rw-r--r--
2025-06-04 09:21
exceptions.o
585.38
KB
-rw-r--r--
2025-06-04 09:22
fileobject.c
16.56
KB
-rw-r--r--
2024-03-19 22:46
fileobject.gcda
6.29
KB
-rw-r--r--
2025-06-04 09:21
fileobject.o
110.28
KB
-rw-r--r--
2025-06-04 09:22
floatobject.c
71.56
KB
-rw-r--r--
2024-03-19 22:46
floatobject.gcda
13
KB
-rw-r--r--
2025-06-04 09:21
floatobject.o
452.61
KB
-rw-r--r--
2025-06-04 09:22
frameobject.c
35.79
KB
-rw-r--r--
2024-03-19 22:46
frameobject.gcda
8.83
KB
-rw-r--r--
2025-06-04 09:21
frameobject.o
199.9
KB
-rw-r--r--
2025-06-04 09:22
funcobject.c
34.36
KB
-rw-r--r--
2024-03-19 22:46
funcobject.gcda
10.05
KB
-rw-r--r--
2025-06-04 09:21
funcobject.o
262.78
KB
-rw-r--r--
2025-06-04 09:22
genericaliasobject.c
18.02
KB
-rw-r--r--
2024-03-19 22:46
genericaliasobject.gcda
6.79
KB
-rw-r--r--
2025-06-04 09:21
genericaliasobject.o
155.11
KB
-rw-r--r--
2025-06-04 09:22
genobject.c
69.94
KB
-rw-r--r--
2024-03-19 22:46
genobject.gcda
12.37
KB
-rw-r--r--
2025-06-04 09:21
genobject.o
327.76
KB
-rw-r--r--
2025-06-04 09:22
interpreteridobject.c
8.74
KB
-rw-r--r--
2024-03-19 22:46
interpreteridobject.gcda
4.75
KB
-rw-r--r--
2025-06-04 09:21
interpreteridobject.o
84.54
KB
-rw-r--r--
2025-06-04 09:22
iterobject.c
16.14
KB
-rw-r--r--
2024-03-19 22:46
iterobject.gcda
6.17
KB
-rw-r--r--
2025-06-04 09:21
iterobject.o
126.71
KB
-rw-r--r--
2025-06-04 09:22
listobject.c
99.53
KB
-rw-r--r--
2024-03-19 22:46
listobject.gcda
18.98
KB
-rw-r--r--
2025-06-04 09:21
listobject.o
739.52
KB
-rw-r--r--
2025-06-04 09:22
listsort.txt
35.31
KB
-rw-r--r--
2024-03-19 22:46
lnotab_notes.txt
8.62
KB
-rw-r--r--
2024-03-19 22:46
longobject.c
174.76
KB
-rw-r--r--
2024-03-19 22:46
longobject.gcda
30.25
KB
-rw-r--r--
2025-06-04 09:21
longobject.o
1.58
MB
-rw-r--r--
2025-06-04 09:22
memoryobject.c
94.86
KB
-rw-r--r--
2024-03-19 22:46
memoryobject.gcda
20.69
KB
-rw-r--r--
2025-06-04 09:21
memoryobject.o
497.3
KB
-rw-r--r--
2025-06-04 09:22
methodobject.c
17.16
KB
-rw-r--r--
2024-03-19 22:46
methodobject.gcda
6.73
KB
-rw-r--r--
2025-06-04 09:21
methodobject.o
172.39
KB
-rw-r--r--
2025-06-04 09:22
moduleobject.c
27.12
KB
-rw-r--r--
2024-03-19 22:46
moduleobject.gcda
10.06
KB
-rw-r--r--
2025-06-04 09:21
moduleobject.o
206.68
KB
-rw-r--r--
2025-06-04 09:22
namespaceobject.c
7.35
KB
-rw-r--r--
2024-03-19 22:46
namespaceobject.gcda
4.75
KB
-rw-r--r--
2025-06-04 09:21
namespaceobject.o
73.17
KB
-rw-r--r--
2025-06-04 09:22
object.c
62.92
KB
-rw-r--r--
2024-03-19 22:46
object.gcda
16.35
KB
-rw-r--r--
2025-06-04 09:21
object.o
427.98
KB
-rw-r--r--
2025-06-04 09:22
obmalloc.c
98.82
KB
-rw-r--r--
2024-03-19 22:46
obmalloc.gcda
13.52
KB
-rw-r--r--
2025-06-04 09:21
obmalloc.o
338.32
KB
-rw-r--r--
2025-06-04 09:22
odictobject.c
73.79
KB
-rw-r--r--
2024-03-19 22:46
odictobject.gcda
11.84
KB
-rw-r--r--
2025-06-04 09:21
odictobject.o
297.43
KB
-rw-r--r--
2025-06-04 09:22
picklebufobject.c
6.03
KB
-rw-r--r--
2024-03-19 22:46
picklebufobject.gcda
4.49
KB
-rw-r--r--
2025-06-04 09:21
picklebufobject.o
54.4
KB
-rw-r--r--
2025-06-04 09:22
rangeobject.c
36.25
KB
-rw-r--r--
2024-03-19 22:46
rangeobject.gcda
8.72
KB
-rw-r--r--
2025-06-04 09:21
rangeobject.o
321.02
KB
-rw-r--r--
2025-06-04 09:22
setobject.c
72.7
KB
-rw-r--r--
2024-03-19 22:46
setobject.gcda
17.04
KB
-rw-r--r--
2025-06-04 09:21
setobject.o
617.43
KB
-rw-r--r--
2025-06-04 09:22
sliceobject.c
19.36
KB
-rw-r--r--
2024-03-19 22:46
sliceobject.gcda
6.45
KB
-rw-r--r--
2025-06-04 09:21
sliceobject.o
146.79
KB
-rw-r--r--
2025-06-04 09:22
structseq.c
16.74
KB
-rw-r--r--
2024-03-19 22:46
structseq.gcda
6.29
KB
-rw-r--r--
2025-06-04 09:21
structseq.o
160.08
KB
-rw-r--r--
2025-06-04 09:22
tupleobject.c
33.24
KB
-rw-r--r--
2024-03-19 22:46
tupleobject.gcda
9.63
KB
-rw-r--r--
2025-06-04 09:21
tupleobject.o
262.6
KB
-rw-r--r--
2025-06-04 09:22
typeobject.c
268.84
KB
-rw-r--r--
2024-03-19 22:46
typeobject.gcda
55.95
KB
-rw-r--r--
2025-06-04 09:21
typeobject.o
1.62
MB
-rw-r--r--
2025-06-04 09:22
typeslots.inc
5.33
KB
-rw-r--r--
2024-03-19 22:46
typeslots.py
1.65
KB
-rwxr-xr-x
2024-03-19 22:46
unicodectype.c
7.49
KB
-rw-r--r--
2024-03-19 22:46
unicodectype.gcda
6.14
KB
-rw-r--r--
2025-06-04 09:21
unicodectype.o
199.91
KB
-rw-r--r--
2025-06-04 09:22
unicodeobject.c
475.94
KB
-rw-r--r--
2024-03-19 22:46
unicodeobject.gcda
108.06
KB
-rw-r--r--
2025-06-04 09:21
unicodeobject.o
3.93
MB
-rw-r--r--
2025-06-04 09:22
unicodetype_db.h
249.58
KB
-rw-r--r--
2024-03-19 22:46
unionobject.c
13.1
KB
-rw-r--r--
2024-03-19 22:46
unionobject.gcda
5.98
KB
-rw-r--r--
2025-06-04 09:21
unionobject.o
139.22
KB
-rw-r--r--
2025-06-04 09:22
weakrefobject.c
31.57
KB
-rw-r--r--
2024-03-19 22:46
weakrefobject.gcda
15.45
KB
-rw-r--r--
2025-06-04 09:21
weakrefobject.o
328.2
KB
-rw-r--r--
2025-06-04 09:22
Save
Rename
// types.GenericAlias -- used to represent e.g. list[int]. #include "Python.h" #include "pycore_object.h" #include "pycore_unionobject.h" // _Py_union_type_or, _PyGenericAlias_Check #include "structmember.h" // PyMemberDef typedef struct { PyObject_HEAD PyObject *origin; PyObject *args; PyObject *parameters; PyObject* weakreflist; } gaobject; static void ga_dealloc(PyObject *self) { gaobject *alias = (gaobject *)self; _PyObject_GC_UNTRACK(self); if (alias->weakreflist != NULL) { PyObject_ClearWeakRefs((PyObject *)alias); } Py_XDECREF(alias->origin); Py_XDECREF(alias->args); Py_XDECREF(alias->parameters); Py_TYPE(self)->tp_free(self); } static int ga_traverse(PyObject *self, visitproc visit, void *arg) { gaobject *alias = (gaobject *)self; Py_VISIT(alias->origin); Py_VISIT(alias->args); Py_VISIT(alias->parameters); return 0; } static int ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) { _Py_IDENTIFIER(__module__); _Py_IDENTIFIER(__qualname__); _Py_IDENTIFIER(__origin__); _Py_IDENTIFIER(__args__); PyObject *qualname = NULL; PyObject *module = NULL; PyObject *r = NULL; PyObject *tmp; int err; if (p == Py_Ellipsis) { // The Ellipsis object r = PyUnicode_FromString("..."); goto done; } if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) { goto done; } if (tmp != NULL) { Py_DECREF(tmp); if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) { goto done; } if (tmp != NULL) { Py_DECREF(tmp); // It looks like a GenericAlias goto use_repr; } } if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) { goto done; } if (qualname == NULL) { goto use_repr; } if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) { goto done; } if (module == NULL || module == Py_None) { goto use_repr; } // Looks like a class if (PyUnicode_Check(module) && _PyUnicode_EqualToASCIIString(module, "builtins")) { // builtins don't need a module name r = PyObject_Str(qualname); goto done; } else { r = PyUnicode_FromFormat("%S.%S", module, qualname); goto done; } use_repr: r = PyObject_Repr(p); done: Py_XDECREF(qualname); Py_XDECREF(module); if (r == NULL) { // error if any of the above PyObject_Repr/PyUnicode_From* fail err = -1; } else { err = _PyUnicodeWriter_WriteStr(writer, r); Py_DECREF(r); } return err; } static PyObject * ga_repr(PyObject *self) { gaobject *alias = (gaobject *)self; Py_ssize_t len = PyTuple_GET_SIZE(alias->args); _PyUnicodeWriter writer; _PyUnicodeWriter_Init(&writer); if (ga_repr_item(&writer, alias->origin) < 0) { goto error; } if (_PyUnicodeWriter_WriteASCIIString(&writer, "[", 1) < 0) { goto error; } for (Py_ssize_t i = 0; i < len; i++) { if (i > 0) { if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) { goto error; } } PyObject *p = PyTuple_GET_ITEM(alias->args, i); if (ga_repr_item(&writer, p) < 0) { goto error; } } if (len == 0) { // for something like tuple[()] we should print a "()" if (_PyUnicodeWriter_WriteASCIIString(&writer, "()", 2) < 0) { goto error; } } if (_PyUnicodeWriter_WriteASCIIString(&writer, "]", 1) < 0) { goto error; } return _PyUnicodeWriter_Finish(&writer); error: _PyUnicodeWriter_Dealloc(&writer); return NULL; } // isinstance(obj, TypeVar) without importing typing.py. // Returns -1 for errors. static int is_typevar(PyObject *obj) { PyTypeObject *type = Py_TYPE(obj); if (strcmp(type->tp_name, "TypeVar") != 0) { return 0; } PyObject *module = PyObject_GetAttrString((PyObject *)type, "__module__"); if (module == NULL) { return -1; } int res = PyUnicode_Check(module) && _PyUnicode_EqualToASCIIString(module, "typing"); Py_DECREF(module); return res; } // 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) { for (Py_ssize_t i = 0; i < len; i++) { if (PyTuple_GET_ITEM(self, i) == item) { return i; } } return -1; } static int tuple_add(PyObject *self, Py_ssize_t len, PyObject *item) { if (tuple_index(self, len, item) < 0) { Py_INCREF(item); PyTuple_SET_ITEM(self, len, item); return 1; } return 0; } PyObject * _Py_make_parameters(PyObject *args) { Py_ssize_t nargs = PyTuple_GET_SIZE(args); Py_ssize_t len = nargs; PyObject *parameters = PyTuple_New(len); if (parameters == NULL) return NULL; Py_ssize_t iparam = 0; for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) { PyObject *t = PyTuple_GET_ITEM(args, iarg); if (PyType_Check(t)) { continue; } int typevar = is_typevar(t); if (typevar < 0) { Py_DECREF(parameters); return NULL; } if (typevar) { iparam += tuple_add(parameters, iparam, t); } else { _Py_IDENTIFIER(__parameters__); PyObject *subparams; if (_PyObject_LookupAttrId(t, &PyId___parameters__, &subparams) < 0) { Py_DECREF(parameters); return NULL; } if (subparams && PyTuple_Check(subparams)) { Py_ssize_t len2 = PyTuple_GET_SIZE(subparams); Py_ssize_t needed = len2 - 1 - (iarg - iparam); if (needed > 0) { len += needed; if (_PyTuple_Resize(¶meters, len) < 0) { Py_DECREF(subparams); Py_DECREF(parameters); return NULL; } } for (Py_ssize_t j = 0; j < len2; j++) { PyObject *t2 = PyTuple_GET_ITEM(subparams, j); iparam += tuple_add(parameters, iparam, t2); } } Py_XDECREF(subparams); } } if (iparam < len) { if (_PyTuple_Resize(¶meters, iparam) < 0) { Py_XDECREF(parameters); return NULL; } } return parameters; } /* 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) { if (PyType_Check(obj)) { Py_INCREF(obj); return obj; } _Py_IDENTIFIER(__parameters__); PyObject *subparams; if (_PyObject_LookupAttrId(obj, &PyId___parameters__, &subparams) < 0) { return NULL; } if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) { Py_ssize_t nparams = PyTuple_GET_SIZE(params); Py_ssize_t nsubargs = PyTuple_GET_SIZE(subparams); PyObject *subargs = PyTuple_New(nsubargs); if (subargs == NULL) { Py_DECREF(subparams); return NULL; } for (Py_ssize_t i = 0; i < nsubargs; ++i) { PyObject *arg = PyTuple_GET_ITEM(subparams, i); Py_ssize_t iparam = tuple_index(params, nparams, arg); if (iparam >= 0) { arg = argitems[iparam]; } Py_INCREF(arg); PyTuple_SET_ITEM(subargs, i, arg); } obj = PyObject_GetItem(obj, subargs); Py_DECREF(subargs); } else { Py_INCREF(obj); } Py_XDECREF(subparams); return obj; } PyObject * _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObject *item) { Py_ssize_t nparams = PyTuple_GET_SIZE(parameters); if (nparams == 0) { return PyErr_Format(PyExc_TypeError, "There are no type variables left in %R", self); } int is_tuple = PyTuple_Check(item); Py_ssize_t nitems = is_tuple ? PyTuple_GET_SIZE(item) : 1; PyObject **argitems = is_tuple ? &PyTuple_GET_ITEM(item, 0) : &item; if (nitems != nparams) { return PyErr_Format(PyExc_TypeError, "Too %s arguments for %R", nitems > nparams ? "many" : "few", self); } /* Replace all type variables (specified by parameters) with corresponding values specified by argitems. t = list[T]; t[int] -> newargs = [int] t = dict[str, T]; t[int] -> newargs = [str, int] t = dict[T, list[S]]; t[str, int] -> newargs = [str, list[int]] */ Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *newargs = PyTuple_New(nargs); if (newargs == NULL) { return NULL; } for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) { PyObject *arg = PyTuple_GET_ITEM(args, iarg); int typevar = is_typevar(arg); if (typevar < 0) { Py_DECREF(newargs); return NULL; } if (typevar) { Py_ssize_t iparam = tuple_index(parameters, nparams, arg); assert(iparam >= 0); arg = argitems[iparam]; Py_INCREF(arg); } else { arg = subs_tvars(arg, parameters, argitems); if (arg == NULL) { Py_DECREF(newargs); return NULL; } } PyTuple_SET_ITEM(newargs, iarg, arg); } return newargs; } PyDoc_STRVAR(genericalias__doc__, "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) { gaobject *alias = (gaobject *)self; // Populate __parameters__ if needed. if (alias->parameters == NULL) { alias->parameters = _Py_make_parameters(alias->args); if (alias->parameters == NULL) { return NULL; } } PyObject *newargs = _Py_subs_parameters(self, alias->args, alias->parameters, item); if (newargs == NULL) { return NULL; } PyObject *res = Py_GenericAlias(alias->origin, newargs); Py_DECREF(newargs); return res; } static PyMappingMethods ga_as_mapping = { .mp_subscript = ga_getitem, }; static Py_hash_t ga_hash(PyObject *self) { gaobject *alias = (gaobject *)self; // TODO: Hash in the hash for the origin Py_hash_t h0 = PyObject_Hash(alias->origin); if (h0 == -1) { return -1; } Py_hash_t h1 = PyObject_Hash(alias->args); if (h1 == -1) { return -1; } return h0 ^ h1; } static PyObject * ga_call(PyObject *self, PyObject *args, PyObject *kwds) { gaobject *alias = (gaobject *)self; PyObject *obj = PyObject_Call(alias->origin, args, kwds); if (obj != NULL) { if (PyObject_SetAttrString(obj, "__orig_class__", self) < 0) { if (!PyErr_ExceptionMatches(PyExc_AttributeError) && !PyErr_ExceptionMatches(PyExc_TypeError)) { Py_DECREF(obj); return NULL; } PyErr_Clear(); } } return obj; } static const char* const attr_exceptions[] = { "__origin__", "__args__", "__parameters__", "__mro_entries__", "__reduce_ex__", // needed so we don't look up object.__reduce_ex__ "__reduce__", "__copy__", "__deepcopy__", NULL, }; static PyObject * ga_getattro(PyObject *self, PyObject *name) { gaobject *alias = (gaobject *)self; if (PyUnicode_Check(name)) { for (const char * const *p = attr_exceptions; ; p++) { if (*p == NULL) { return PyObject_GetAttr(alias->origin, name); } if (_PyUnicode_EqualToASCIIString(name, *p)) { break; } } } return PyObject_GenericGetAttr(self, name); } static PyObject * ga_richcompare(PyObject *a, PyObject *b, int op) { if (!_PyGenericAlias_Check(b) || (op != Py_EQ && op != Py_NE)) { Py_RETURN_NOTIMPLEMENTED; } if (op == Py_NE) { PyObject *eq = ga_richcompare(a, b, Py_EQ); if (eq == NULL) return NULL; Py_DECREF(eq); if (eq == Py_True) { Py_RETURN_FALSE; } else { Py_RETURN_TRUE; } } gaobject *aa = (gaobject *)a; gaobject *bb = (gaobject *)b; int eq = PyObject_RichCompareBool(aa->origin, bb->origin, Py_EQ); if (eq < 0) { return NULL; } if (!eq) { Py_RETURN_FALSE; } return PyObject_RichCompare(aa->args, bb->args, Py_EQ); } static PyObject * ga_mro_entries(PyObject *self, PyObject *args) { gaobject *alias = (gaobject *)self; return PyTuple_Pack(1, alias->origin); } static PyObject * ga_instancecheck(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyErr_SetString(PyExc_TypeError, "isinstance() argument 2 cannot be a parameterized generic"); return NULL; } static PyObject * ga_subclasscheck(PyObject *self, PyObject *Py_UNUSED(ignored)) { PyErr_SetString(PyExc_TypeError, "issubclass() argument 2 cannot be a parameterized generic"); return NULL; } static PyObject * ga_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) { gaobject *alias = (gaobject *)self; return Py_BuildValue("O(OO)", Py_TYPE(alias), alias->origin, alias->args); } static PyObject * ga_dir(PyObject *self, PyObject *Py_UNUSED(ignored)) { gaobject *alias = (gaobject *)self; PyObject *dir = PyObject_Dir(alias->origin); if (dir == NULL) { return NULL; } PyObject *dir_entry = NULL; for (const char * const *p = attr_exceptions; ; p++) { if (*p == NULL) { break; } else { dir_entry = PyUnicode_FromString(*p); if (dir_entry == NULL) { goto error; } int contains = PySequence_Contains(dir, dir_entry); if (contains < 0) { goto error; } if (contains == 0 && PyList_Append(dir, dir_entry) < 0) { goto error; } Py_CLEAR(dir_entry); } } return dir; error: Py_DECREF(dir); Py_XDECREF(dir_entry); return NULL; } static PyMethodDef ga_methods[] = { {"__mro_entries__", ga_mro_entries, METH_O}, {"__instancecheck__", ga_instancecheck, METH_O}, {"__subclasscheck__", ga_subclasscheck, METH_O}, {"__reduce__", ga_reduce, METH_NOARGS}, {"__dir__", ga_dir, METH_NOARGS}, {0} }; static PyMemberDef ga_members[] = { {"__origin__", T_OBJECT, offsetof(gaobject, origin), READONLY}, {"__args__", T_OBJECT, offsetof(gaobject, args), READONLY}, {0} }; static PyObject * ga_parameters(PyObject *self, void *unused) { gaobject *alias = (gaobject *)self; if (alias->parameters == NULL) { alias->parameters = _Py_make_parameters(alias->args); if (alias->parameters == NULL) { return NULL; } } Py_INCREF(alias->parameters); return alias->parameters; } static PyGetSetDef ga_properties[] = { {"__parameters__", ga_parameters, (setter)NULL, "Type variables in the GenericAlias.", NULL}, {0} }; /* 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) { if (!PyTuple_Check(args)) { args = PyTuple_Pack(1, args); if (args == NULL) { return 0; } } else { Py_INCREF(args); } Py_INCREF(origin); alias->origin = origin; alias->args = args; alias->parameters = NULL; alias->weakreflist = NULL; return 1; } static PyObject * ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { if (!_PyArg_NoKeywords("GenericAlias", kwds)) { return NULL; } if (!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 2)) { return NULL; } PyObject *origin = PyTuple_GET_ITEM(args, 0); PyObject *arguments = PyTuple_GET_ITEM(args, 1); gaobject *self = (gaobject *)type->tp_alloc(type, 0); if (self == NULL) { return NULL; } if (!setup_ga(self, origin, arguments)) { Py_DECREF(self); return NULL; } return (PyObject *)self; } static PyNumberMethods ga_as_number = { .nb_or = _Py_union_type_or, // Add __or__ function }; // TODO: // - argument clinic? // - cache? PyTypeObject Py_GenericAliasType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) .tp_name = "types.GenericAlias", .tp_doc = genericalias__doc__, .tp_basicsize = sizeof(gaobject), .tp_dealloc = ga_dealloc, .tp_repr = ga_repr, .tp_as_number = &ga_as_number, // allow X | Y of GenericAlias objs .tp_as_mapping = &ga_as_mapping, .tp_hash = ga_hash, .tp_call = ga_call, .tp_getattro = ga_getattro, .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, .tp_traverse = ga_traverse, .tp_richcompare = ga_richcompare, .tp_weaklistoffset = offsetof(gaobject, weakreflist), .tp_methods = ga_methods, .tp_members = ga_members, .tp_alloc = PyType_GenericAlloc, .tp_new = ga_new, .tp_free = PyObject_GC_Del, .tp_getset = ga_properties, }; PyObject * Py_GenericAlias(PyObject *origin, PyObject *args) { gaobject *alias = (gaobject*) PyType_GenericAlloc( (PyTypeObject *)&Py_GenericAliasType, 0); if (alias == NULL) { return NULL; } if (!setup_ga(alias, origin, args)) { Py_DECREF(alias); return NULL; } return (PyObject *)alias; }