3 ms·
I tried it on this bit of code, but it didn't detect a type mismatch. Is it supposed to? def foo(n: int): pass def bar(): foo("123") It does
by ryanprichard 11y ago
I tried it on this bit of code, but it didn't detect a type mismatch. Is it supposed to?
def foo(n: int):
pass
def bar():
foo("123")
It does detect this mismatch:
def foo(n: int):
pass
foo("123")
- ddfisher 11y agoThis is intended behavior, actually! By default, mypy doesn't type check the interior of functions that don't have any type annotations. This lets you slowly introduce types to a large codebase without having to convert everything at once (or even file by file). Adding a type annotation to "bar" will cause mypy to check it: def foo(n: int): pass def bar() -> None: foo("123") >> main: note: In function "bar": >> main:4: error: Argument 1 to "foo" has incompatible type "str"; expected "int"