by Manuel Ceron for
Function annotations (PEP 3107) are a powerful and interesting feature of Python that no one is using. This talk presents three practical use cases that can make developer’s life better.
Type annotations for better tooling support and early error detection. Code analyzers, linters and IDEs can use type annotations to make smarter suggestions and show errors just after typing.
Logic predicate annotations and design by contract. Adding preconditions and postconditions to your functions in an expressive way.
Documentation consistency and auto-documentation. By enforcing annotations, it’s possible to check the consistency of docstrings or even create them automatically.
Here is a small library I wrote implementing some of the concepts I will discuss in the talk: typeannotations