Type Hints in Python

Type Hints in Python: Type Hints: Saying What a Value Should Be, Checking Types with mypy.

Updated

  1. Type Hints: Saying What a Value Should Be (Apprentice): A type hint is a label on a variable, a parameter or a return value that says what kind of value belongs there, such as float, list[float] or a string that may be None, so people and tools can see what a function expects without reading its body.
  2. Checking Types with mypy (Journeyman): mypy reads your type hints and every call without running the code, and reports each place where a value can't be what its hint promises, such as text passed as a price or a None that the next line uses as text.