Created
March 31, 2023 01:21
-
-
Save mypy-play/2a8773ad5ba9253ac8933ad67b240010 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 import TypeVar, Union | |
T = TypeVar("T") | |
Thing = Union[str, int] | |
MaybeTuple = Union[T, tuple[T]] | |
def untuple(item: MaybeTuple[T]) -> T: | |
if isinstance(item, tuple): | |
return item[0] | |
return item | |
def test_func(var: MaybeTuple[Thing]): | |
reveal_type(untuple(var)) # object in mypy, str | int (==Thing) in pyright |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment