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>
This commit is contained in:
Ken Jin 2021-07-24 22:49:25 +08:00 committed by GitHub
parent 9356d1e47d
commit ca5a4cf826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 94 deletions

View file

@ -375,6 +375,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()")