-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support new union type syntax with isinstance (#10775)
Support things like `isinstance(x, int | str)` in Python 3.10 Closes #9880.
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# For Python 3.10+ only | ||
from typing import Tuple, TypeVar, Generic, Union, cast, Any, Type | ||
import types | ||
|
||
T = TypeVar('T') | ||
|
||
class object: | ||
def __init__(self) -> None: pass | ||
|
||
class type(Generic[T]): | ||
def __init__(self, x) -> None: pass | ||
def __or__(self, x) -> types.Union: pass | ||
|
||
class tuple(Generic[T]): pass | ||
|
||
class function: pass | ||
|
||
def isinstance(x: object, t: Union[Type[object], Tuple[Type[object], ...], types.Union]) -> bool: pass | ||
def issubclass(x: object, t: Union[Type[object], Tuple[Type[object], ...]]) -> bool: pass | ||
|
||
class int: | ||
def __add__(self, other: 'int') -> 'int': pass | ||
class float: pass | ||
class bool(int): pass | ||
class str: | ||
def __add__(self, other: 'str') -> 'str': pass | ||
class ellipsis: pass | ||
|
||
NotImplemented = cast(Any, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters