optional type
Domain: Validation Typing
π― Motivation
Optional marks a value as either a specific type or None. It communicates intent clearly and helps type checkers warn you when you forget to handle the None case.
π Concrete Example
def find_user(id: int) -> Optional[User]: tells callers the result might be None, and mypy warns if you access .name without checking for None first.
π Analogy
Optional is like a parking spot labeled βvehicle or empty.β You must check if a car is there before trying to drive it, or you will crash (into a NoneType error).