mirror of
https://github.com/python/cpython.git
synced 2025-09-16 21:56:14 +00:00
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:
parent
9356d1e47d
commit
ca5a4cf826
3 changed files with 26 additions and 94 deletions
|
@ -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()")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue