Skip to content

Instantly share code, notes, and snippets.

@kkismd
Created May 12, 2018 09:36
Show Gist options
  • Save kkismd/50c95f0b260f654407ab6e33da693f2d to your computer and use it in GitHub Desktop.
Save kkismd/50c95f0b260f654407ab6e33da693f2d to your computer and use it in GitHub Desktop.
mypy why
class Dog():
def __init__(self, name: str) -> None:
self.name: str = name
def bark(self) -> str:
return "Bow-wow (" + self.name + ")"
def test():
# No mypy error, but causes Rutime error at next line!!!
dog = Dog(123)
dog.bark()
test()
# mypy: error: Argument 1 to "Dog" has incompatible type "int"; expected "str"
dog = Dog(123)
dog.bark()
@kkismd
Copy link
Author

kkismd commented May 12, 2018

Why not error in line 10?

$ mypy dog.py
dog.py:16: error: Argument 1 to "Dog" has incompatible type "int"; expected "str"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment