Type hints aiding maintainability—not runtime magic

Beginner Accelerating numerics & developer hygiene
Created by Pavel · 29.04.2026 at 19:11 UTC

PEP 484 annotations document expected types for humans and for static checkers (mypy, pyright, basedpyright). CPython does not enforce them at runtime by default—x: int = "oops" is legal until a tool or TypedDict/dataclass validation complains elsewhere.

In data science codebases, hints on function boundaries (DataFrame in, Series out) catch shape/API drift before CI fails in production. Pair hints with tests and optional runtime validation where needed (Pydantic, beartype).

Typing module docs: [1].


Sources

University approvals: 0
Tasks
Question 1

Without running mypy/pyright, what does def f(x: int) -> int: return x guarantee at runtime in stock CPython?

Hint

Runtime vs static typing.

Question 2

Why do teams still add type hints to pandas-heavy code if enforcement is optional?

Hint

Documentation + static analysis.

Question 3

clamp(x, lo, hi) returns max(lo, min(x, hi)) for floats.

Hint

Order of min/max encodes clamping.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Accelerating numerics & developer hygiene
  • Difficulty: Beginner
  • Completed: 0 users
Creator
Pavel
Pavel