bpo-42233: Add union type expression support for GenericAlias and fix de-duplicating of GenericAlias (GH-23077)

This commit is contained in:
kj 2020-11-09 12:00:13 +08:00 committed by GitHub
parent 23831a7a90
commit 4eb41d055e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 17 deletions

View file

@ -6,7 +6,7 @@
#include "pycore_object.h"
#include "pycore_pyerrors.h"
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_unionobject.h" // _Py_Union()
#include "pycore_unionobject.h" // _Py_Union(), _Py_union_type_or
#include "frameobject.h"
#include "structmember.h" // PyMemberDef
@ -3789,19 +3789,9 @@ type_is_gc(PyTypeObject *type)
return type->tp_flags & Py_TPFLAGS_HEAPTYPE;
}
static PyObject *
type_or(PyTypeObject* self, PyObject* param) {
PyObject *tuple = PyTuple_Pack(2, self, param);
if (tuple == NULL) {
return NULL;
}
PyObject *new_union = _Py_Union(tuple);
Py_DECREF(tuple);
return new_union;
}
static PyNumberMethods type_as_number = {
.nb_or = (binaryfunc)type_or, // Add __or__ function
.nb_or = _Py_union_type_or, // Add __or__ function
};
PyTypeObject PyType_Type = {