Skip to content

Instantly share code, notes, and snippets.

@arusahni
Created June 19, 2020 19:09
Show Gist options
  • Save arusahni/1e4bf87618a9ec8382a7bd5e52828442 to your computer and use it in GitHub Desktop.
Save arusahni/1e4bf87618a9ec8382a7bd5e52828442 to your computer and use it in GitHub Desktop.
MyPy fail
#!/usr/bin/env python3
import mod
def do_the_thing():
bar = mod.get_optional_bar()
print(bar.x)
if __name__ == "__main__":
do_the_thing()
import random
from dataclasses import dataclass
from typing import Optional
@dataclass
class Bar:
x: int
def get_optional_bar() -> Optional[Bar]:
if random.randint(0, 1):
return Bar(1)
return None
$ mypy main.py
Success: no issues found in 1 source file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment