Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 24, 2024 17:37
Show Gist options
  • Save mypy-play/92bc99dae8414061df41d5cb533fd9b1 to your computer and use it in GitHub Desktop.
Save mypy-play/92bc99dae8414061df41d5cb533fd9b1 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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