Created
October 8, 2019 21:23
-
-
Save johnsondnz/2350ba547195f8a53559815d20bcdd4f to your computer and use it in GitHub Desktop.
Small example on Python Typing
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 | |
def testing(a: int, b: int) -> int: | |
return a + b | |
print(testing(1,2)) | |
from typing import Dict | |
from mypy_extensions import TypedDict | |
TestDict = TypedDict( | |
"TestDict", | |
{ | |
"Key1": int, | |
"Key2": str | |
} | |
) | |
print(TestDict( | |
Key1=1,Key2=2 | |
)) | |
""" | |
/tmp ⌚ 10:16:53 | |
$ mypy test.py | |
test.py:20: error: Incompatible types (expression has type "int", TypedDict item "Key2" has type "str") | |
Found 1 error in 1 file (checked 1 source file) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment