bpo-44731: Simplify the union type implementation (GH-27318) (GH-27334)
Remove direct support of typing types in the C code because they are already supported by defining methods __or__ and __ror__ in the Python code.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Lib/typing.py b/Lib/typing.py
index e2fb7d1..0570b4e 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -375,6 +375,12 @@ def __reduce__(self):
def __call__(self, *args, **kwds):
raise TypeError(f"Cannot instantiate {self!r}")
+ def __or__(self, other):
+ return Union[self, other]
+
+ def __ror__(self, other):
+ return Union[other, self]
+
def __instancecheck__(self, obj):
raise TypeError(f"{self} cannot be used with isinstance()")