Sponsored Reserved space — layout preview until AdSense is connected

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 + "! ") * times

Why 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.

Comments

Questions, corrections, and tips stay visible for everyone reading this page.

0 in thread

Join the discussion

Shown next to your comment.

Constructive tone · up to 4,000 characters

No comments yet

Be the first to leave a note — it helps the next reader.

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected