Python Type Annotations
Start with the docs and the Type hints cheat sheet
Topics for consideration:
- syntax shorthands e.g.
|
for Union or Optional - Self
- If you are using the typing library then there is an abstract type class provided for asynchronous context managers AsyncContextManager[T], where T is the type of the object which will be bound by the as clause of the async with statement.
- mypy
If you are using typing then there is an abstract class Awaitable
which is generic, so that Awaitable[R]
for some type R means anything which is awaitable, and when used in an await statement will return something of type R.