Created
May 14, 2025 11:35
-
-
Save mypy-play/f5f9f5437041d07489d876a8d0b2da98 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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
import typing as t | |
@t.overload | |
def stuff(isnone: t.Literal[True] = ...) -> None: | |
... | |
@t.overload | |
def stuff(isnone: t.Literal[False] = ...) -> str: | |
... | |
def stuff(isnone: bool = False) -> str | None: | |
if isnone: | |
return None | |
else: | |
return 'ᕕ( ᐛ )ᕗ' | |
a = stuff(True) | |
t.reveal_type(a) # expected None -> ok | |
b = stuff(False) | |
t.reveal_type(b) # expected builtins.str -> ok | |
c = stuff() # default is False | |
t.reveal_type(c) # expected builtins.str -> nope... got None v_v | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment