Skip to content

Instantly share code, notes, and snippets.

@tusharsadhwani
Created May 5, 2021 19:09
from typing import Dict, TypeVar, Union
T = TypeVar('T')
MyOptional = Union[T, None]
def get_unicorn(d: Dict[str, int]) -> MyOptional[int]:
return d.get('unicorn')
d = {'x': 5}
unicorn = get_unicorn(d)
reveal_type(unicorn) # Union[int, None]
print(unicorn) # None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment