Tech
Type hints in Python — catch bugs before you run the code
How annotations plus a checker like mypy or Pyright turn whole classes of mistakes into editor warnings.
May 2026 · 7 min read · 1 views · 0 hearts
Type hints are optional annotations that document what a function expects and returns. Python ignores them at runtime, but tools read them to flag mismatches.
Annotating a function
def greet(name: str, times: int = 1) -> str:
return ("Hi " + name + "! ") * timesWhy bother
A checker such as mypy or Pyright will catch passing the wrong type, forgetting a return, or accessing a missing attribute — without executing anything. Your editor surfaces these as you type.
Start small
You do not need to annotate everything at once. Add hints to public functions and shared modules first; the value compounds as coverage grows.
Sponsored
Comments
Questions, corrections, and tips stay visible for everyone reading this page.
Join the discussion
No comments yet
Be the first to leave a note — it helps the next reader.