Re:Mypy 0.3 Released – optional static type checker for Python
by ryanprichard on Friday February 19, 2016 @09:37PM
(#11138443)
I tried it on this bit of code, but it didn't detect a type mismatch. Is it supposed to?
It does detect this mismatch:
[ Parent
| on HN ]
Re:Mypy 0.3 Released – optional static type checker for Python
by ddfisher on Friday February 19, 2016 @10:01PM
(#11138536)
This 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"