# example.py def add_numbers(a: int, b: int) ->int: return a + b
result = add_numbers("5","3")# 这里有问题!传入了字符串
运行 mypy 检查:
mypy example.py
你会看到类似这样的输出:
example.py:4: error:Argument1 to "add_numbers" has incompatible type "str"; expected "int"
example.py:4: error:Argument2 to "add_numbers" has incompatible type "str"; expected "int"Found2 errors in1 file (checked1 source file)