Typing
This folder has no README. Everything inside it is listed below.
Notes
- Type hint basics: Optional, Union, Callable Type hints (PEP 484+) document intent and let static checkers like mypy and pyright catch bugs without running code.
- TypeVar and generics TypeVar lets you write functions and classes that preserve type relationships across parameters and return values, instead of erasing to Any.
- Protocol and structural typing Protocol (PEP 544) gives Python static duck typing — types that match by shape (methods/attributes) rather than by inheritance.
- TypedDict, Literal, Final, ClassVar Four small but high-impact tools for precise typing.
- Annotated and TypeGuard Two advanced typing features that bridge static typing and runtime semantics.
- ParamSpec and Concatenate — typing decorators ParamSpec (PEP 612, Python 3.10+) lets you type decorators and higher-order functions that preserve the original signature, instead of erasing to…
- mypy vs pyright; strictness modes; runtime enforcement For new projects, pyright (via Pylance) is becoming the default for editor-driven typing. mypy is widely deployed in CI.
- Type-driven development: make illegal states unrepresentable 4 The idea from Haskell and Rust culture, now practical in Python: design the types so that an invalid state cannot be constructed, and a whole class of…