Created
June 19, 2020 19:09
-
-
Save arusahni/1e4bf87618a9ec8382a7bd5e52828442 to your computer and use it in GitHub Desktop.
MyPy fail
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
#!/usr/bin/env python3 | |
import mod | |
def do_the_thing(): | |
bar = mod.get_optional_bar() | |
print(bar.x) | |
if __name__ == "__main__": | |
do_the_thing() |
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 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 |
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
$ 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