aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkj <28750310+Fidget-Spinner@users.noreply.github.com>2020-11-09 12:00:13 +0800
committerGitHub <noreply@github.com>2020-11-08 20:00:13 -0800
commit4eb41d055e8307b8206f680287e492a6db068acd (patch)
tree49f5dd4d1abac0b43945310972a97e0c943d2869 /Objects/genericaliasobject.c
parentbpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075) (diff)
downloadcpython-4eb41d055e8307b8206f680287e492a6db068acd.tar.gz
cpython-4eb41d055e8307b8206f680287e492a6db068acd.tar.bz2
cpython-4eb41d055e8307b8206f680287e492a6db068acd.zip
bpo-42233: Add union type expression support for GenericAlias and fix de-duplicating of GenericAlias (GH-23077)
Diffstat (limited to 'Objects/genericaliasobject.c')
-rw-r--r--Objects/genericaliasobject.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c
index 6508c69cbf7..28ea487a44f 100644
--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -2,6 +2,7 @@
#include "Python.h"
#include "pycore_object.h"
+#include "pycore_unionobject.h" // _Py_union_as_number
#include "structmember.h" // PyMemberDef
typedef struct {
@@ -573,6 +574,10 @@ ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return Py_GenericAlias(origin, arguments);
}
+static PyNumberMethods ga_as_number = {
+ .nb_or = (binaryfunc)_Py_union_type_or, // Add __or__ function
+};
+
// TODO:
// - argument clinic?
// - __doc__?
@@ -586,6 +591,7 @@ PyTypeObject Py_GenericAliasType = {
.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,