Type Hints and mypy: Catch Data Bugs Before You Run
Mypy reported 4 errors from 3 bugs without running the code, and missed a wrong average.
Video #145 ยท Python for data
Steps in the video
Files
- bad.py (34 lines)
- blind.py (14 lines)
- good.py (36 lines)
- run.py (17 lines)
Tested with
Python 3.12.15 | mypy==2.4.0
What this does not show
Made-up orders and three bugs I wrote on purpose; standard library only, so no data frames were tested; one mypy version, two runs; mypy skips functions without hints by default.
Sources
Learning IT by Example.