Skip to content

Chapter 2 of 7

Type annotations and static checkers

A Python annotation is recorded on the function object and then ignored: the interpreter never consults it, so a signature enforces nothing until a separate program reads it. This chapter shows what the interpreter does with an annotation, annotates a real signature end to end including optionals, unions, container element types and generics, and runs mypy and pyright over the result — default settings against strict ones, and the wiring that makes the check a gate rather than a suggestion.

Python for AI work — read the current version at https://daviddominguez.dev/learn/en/python-for-ai-work/type-annotations-and-static-checkers

Back to top