Practical tips for introducing mypy to existing Python projects. Covers ensuring mypy is actually running and finding all source files, where to manually supply types (function arguments and return types), the importance of Optional for nullable values, whether to include tests in type checking, handling third-party stubs for

12m read timeFrom calpaterson.com
Post cover image
Table of contents
First ensure that mypy really is being runWhere to supply types manuallyOptional comes up a lotConsider whether to include your testsBe selective about the usage of third-party stubsEscape hatches are occasionally necessaryPrioritise a few choice strictness optionsHow to debug type issuesAbstract, concrete, mutable and immutableTyped dataclassesTypedDictGenerics and type variablesABCs vs ProtocolsThe final tipContact/etcSee also

Sort: