Created
June 5, 2024 03:04
-
-
Save msakai/86f9d8c0ee24918ea381e31923a4944c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Literal, Optional, Tuple, overload | |
@overload | |
def f(with_extra_info: Literal[False]) -> Tuple[int, int]: ... | |
@overload | |
def f(with_extra_info: Literal[True]) -> Tuple[int, int, str]: ... | |
# This overload is necessafy for type checking the last `f(with_extra_info)`. | |
@overload | |
def f(with_extra_info: bool) -> Tuple[int, int] | Tuple[int, int, str]: ... | |
def f(with_extra_info: bool) -> Tuple[int, int] | Tuple[int, int, str]: | |
if with_extra_info: | |
return (0, 1, 'extra info') | |
else: | |
return (0, 1) | |
with_extra_info: bool = True | |
extra_info: Optional[str] | |
if with_extra_info: | |
a, b, extra_info = f(with_extra_info) | |
else: | |
a, b = f(with_extra_info) | |
extra_info = None | |
f(with_extra_info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment