'What can MyPy detect and what can it not?
I just started with MyPy to add more static typing to my python programs. I tried this:
import sys
def summe (a: int, b: int):
print (a + b)
def main():
x: int = 10
y: int = 20
z: str = '30'
summe (x, y)
summe (x, z)
if __name__ == '__main__':
sys.exit(main())
and this is obviously a type error and crashes at runtime but MyPy says: Success: no issues found in 1 source file
Am I doing something wrong, missed some setting? I have Windows 10, Python 3.10, latest MyPy under Eclipse.
Solution 1:[1]
Your main is not being type-checked as you have not annotated it. Add the annotation:
def main() -> None:
And the second summe call will cause a type error as you expect.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | yuri kilochek |
