Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created July 22, 2024 11:38
Show Gist options
  • Save mypy-play/5611cc5fb5ddbb68e7ff3618ded6962e to your computer and use it in GitHub Desktop.
Save mypy-play/5611cc5fb5ddbb68e7ff3618ded6962e to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import Literal, Optional, overload
@overload
def gimme(x: Literal[True]) -> str: ...
@overload
def gimme(x: Literal[False]) -> None: ...
@overload
def gimme(x: bool) -> Optional[str]: ...
def gimme(x: bool) -> Optional[str]:
if x:
return "yes"
else:
return None
a: int = gimme(True)
b: int = gimme(False)
c: int = gimme(3 % 2 == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment