The typing module introduced in Python 3.5 (and available on PyPI for older versions of
Python 3) is supported. See below for details.

There are two principal ways to use type checking, each with its pros and cons:

calling check_argument_types() from within the function body:

debugger friendly but cannot check the type of the return value

decorating the function with @typechecked:

can check the type of the return value but adds an extra frame to the call stack for every call
to a decorated function

If a function is called with incompatible argument types or a @typechecked decorated function
returns a value incompatible with the declared type, a descriptive TypeError exception is
raised.

Type checks can be fairly expensive so it is recommended to run Python in “optimized” mode
(python -O or setting the PYTHONOPTIMIZE environment variable) when running code containing
type checks in production. The optimized mode will disable the type checks, by virtue of removing
all assert statements and setting the __debug__ constant to False.