Chapter 7 Python Type Hints
Throughout this book, almost all the examples have included type hints. Python added syntax for “annotations” back in Python 3.0. (See PEP 3107: https://peps.python.org/pep-3107/.) This syntax was applied to the problem of type hints starting with Python 3.6. (See PEP 526: https://peps.python.org/pep-0526/.) Since then, the idea of a formalized type system has evolved and grown.
Currently, the details are in https://typing.readthedocs.io/en/latest/spec/. This document describes the type system in detail.
The type hints are optional, and some developers feel they’re a burden because it’s slightly more code that they have to think about.
The type hints provide important clarification, and many developers feel they’re ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access