--- name: strict-mypy description: Enforces strict MyPy type checking conventions matching the project's pyproject.toml configuration. Use whenever writing or modifying Python code. --- # Strict MyPy Typing Standards This project uses a highly strict MyPy configuration (`strict = true`). When writing or refactoring Python code, you MUST adhere to the following rules to ensure the code passes type checking: ## 1. Absolute Signature Completeness - EVERY function and method must have fully typed arguments and a return type (`disallow_untyped_defs`, `disallow_incomplete_defs`). - ALWAYS specify `-> None` for functions and methods that do not return a value. - NEVER leave type hints partially defined (e.g., typing only some arguments). - Decorators must be completely type-hinted using `typing.Callable` or `typing.ParamSpec` (`disallow_untyped_decorators`). ## 2. No Implicit Optionals - `arg: str = None` is strictly forbidden. - You MUST explicitly union with None: `arg: str | None = None` (`no_implicit_optional`). ## 3. Strict Generics - NEVER use bare collections as types. - ALWAYS specify the inner types: use `list[str]`, `dict[str, int]`, or `tuple[int, ...]` instead of bare `list`, `dict`, or `tuple` (`disallow_any_generics`). ## 4. Restrictions on `Any` and Subclassing - Do not subclass from untyped external libraries or `Any` (`disallow_subclassing_any`). - Avoid using external types that have no stubs and resolve to `Any` (`disallow_any_unimported`). - Refrain from returning `Any` to avoid contaminating the type inference of calling functions (`warn_return_any`). ## 5. Pydantic Strictness - `pydantic.mypy` is active with strict initialization. - When instantiating Pydantic models, ensure you are passing exactly the expected typed arguments, as extra or untyped arguments will fail type checks (`init_typed = true`, `init_forbid_extra = true`).