Build Status Code Coverage Documentation

This library provides run-time type checking for functions defined with PEP 484 argument (and return) type annotations.

Three principal ways to do type checking are provided, each with its pros and cons:

  1. the check_argument_types() and check_return_type() functions:

    • debugger friendly (except when running with the pydev debugger with the C extension installed)

    • does not work reliably with dynamically defined type hints (e.g. in nested functions)

  2. the @typechecked decorator:

    • automatically type checks yields and sends of returned generators (regular and async)

    • adds an extra frame to the call stack for every call to a decorated function

  3. the import hook (typeguard.importhook.install_import_hook()):

    • automatically annotates classes and functions with @typechecked on import

    • no code changes required in target modules

    • requires imports of modules you need to check to be deferred until after the import hook has been installed

    • may clash with other import hooks