I try writing the type hint explicitly in the definition of the function
# test.py
def annotated(x: int, y: str) -> bool:
return x < y
ran python3.5 -m mypy test.py
and got following message
test.py:2: error: Unsupported operand types for > ("str" and "int")
It's correct. But when I try using stub file
# test.py
def annotated(x, y):
return x < y
# test.pyi
def annotated(x: int, y: str) -> bool: ...
I got nothing. I saw this answer Using Mypy local stubs. So I try to import
.
from test import annotated
annotated(2, 3)
It's ok. I got
error: Argument 2 to "annotated" has incompatible type "int"; expected "str"
But call annotated(2, 's')
still got nothing.
So What should I do to check illegal operation with a stub file? Thanks