summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-07-24 13:34:48 (GMT)
committerGitHub <noreply@github.com>2021-07-24 13:34:48 (GMT)
commit08284231275ac9cc60ae27eab2338805919d8881 (patch)
tree4d61a5ef20902208d8615ac052e39d070e85c73d /Lib/typing.py
parent3eae8f20d7b6f88d3618b0afc94893165a914022 (diff)
downloadcpython-08284231275ac9cc60ae27eab2338805919d8881.zip
cpython-08284231275ac9cc60ae27eab2338805919d8881.tar.gz
cpython-08284231275ac9cc60ae27eab2338805919d8881.tar.bz2
bpo-44731: Simplify the union type implementation (GH-27318)
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.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 198837c..3403f55 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -383,6 +383,12 @@ class _SpecialForm(_Final, _root=True):
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()")