Why this matters
Type hints prevent whole classes of bugs and improve IDE/refactor support.
Annotate function parameters and return types; use TypedDict/Protocol/Dataclass/Pydantic where appropriate.
Type hints prevent whole classes of bugs and improve IDE/refactor support.
Side-by-side examples engineers can pattern-match during review.
def total(items):
return sum(i['price'] * i['qty'] for i in items)from typing import TypedDict, Iterable
class Line(TypedDict):
price: float
qty: int
def total(items: Iterable[Line]) -> float:
return sum(i['price'] * i['qty'] for i in items)def f(x): ...def f(x: int) -> str: ...From the same buckets as this rule.