I donβt know why someone voted for this question without answering it or commenting on why he / she does not like him, but here is the answer I found out:
The mypy stub file only works when importing a module. So, if you have
def try_check(a): pass
in kk.py and
def try_check(a: int):...
in kk.pyi in the same directory with kk.py or in the directory that sets MYPYPATH, mypy will type the python file check if you import kk. This is if you
import .kk kk.try_check('str')
in test.py and run mypy test.py, mypy will report a type conflict. However, it will not report a conflict if you have
try_check('str')
at kk.py.
You can enter validation functions in a program that contains a function definition. If you write an input hint explicitly in the function definition. For example, you can write
def try_check(a: int): pass try_check('str')
in kk.py and then mypy kk.py. Mypy will report a type conflict.
source share