Search notes:

PEP 484 - Type Hints

PEP 484 defined type annotations.

Annotated arguments and returns types stored in __annotations__

At runtime, the annotated arguments and return types are accessible through __annotations__.
The following script prints {'t': <class 'str'>, 'n': <class 'int'>, 'return': None}
def f(t: str, n: int = 4):
    """Function that prints value of its first argument n times (the second argument)"""
    for _ in range(n): print(t)

# f('hello world')

print(f.__annotations__)

No runtime checking

Although the annotations are stored in __annotations__, no actual type checking takes place at runtime!
In fact, the PEP explicitely states that
Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory, even by convention.

Challenges

A challenge with fully-annotated code is that it increases the number of required import statements which has been recognized by
It seems that typing.TYPE_CHECKING was a result of these PEPs, but see also PEP 781 (Make TYPE_CHECKING a built-in constant)

See also

The typing stdlib module.
PEP 484 was inspired by mypy.
A small list of other interesting PEPs such as PEP 3107 which added support for arbitrary annotations on parts of a function definition.
Functions with the @no_type_check decorator should be treated as having no annotations.

Index