mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
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.
This commit is contained in:
parent
3eae8f20d7
commit
0828423127
3 changed files with 26 additions and 94 deletions
|
|
@ -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()")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue