📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Python from Zero Type Checking with mypy

Type Checking with mypy

4 min read
mypy is a static type checker. Run mypy src/ to find type errors without running code. Configure with pyproject.toml. It catches bugs like passing the wrong type to a function before they become runtime errors.

Static Type Checking

pip install mypy

# code.py
def greet(name: str) -> str:
    return f"Hello, {name}!"

greet(42)  # mypy will catch this!

# Run
mypy code.py
# error: Argument 1 to "greet" has incompatible type "int"; expected "str"