Created
May 24, 2024 17:37
-
-
Save mypy-play/92bc99dae8414061df41d5cb533fd9b1 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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
from typing_extensions import TypeIs | |
from typing import Any, Awaitable, TypeVar, Union | |
T = TypeVar('T') | |
def is_awaitable(val: object) -> TypeIs[Awaitable[Any]]: pass | |
def main(a: Union[Awaitable[T], T]) -> None: | |
if is_awaitable(a): | |
reveal_type(a) # N: Revealed type is "Union[typing.Awaitable[T`-1], typing.Awaitable[Any]]" | |
else: | |
reveal_type(a) # N: Revealed type is "T`-1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment