README.rst 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. .. image:: https://travis-ci.com/agronholm/typeguard.svg?branch=master
  2. :target: https://travis-ci.com/agronholm/typeguard
  3. :alt: Build Status
  4. .. image:: https://coveralls.io/repos/agronholm/typeguard/badge.svg?branch=master&service=github
  5. :target: https://coveralls.io/github/agronholm/typeguard?branch=master
  6. :alt: Code Coverage
  7. .. image:: https://readthedocs.org/projects/typeguard/badge/?version=latest
  8. :target: https://typeguard.readthedocs.io/en/latest/?badge=latest
  9. This library provides run-time type checking for functions defined with
  10. `PEP 484 <https://www.python.org/dev/peps/pep-0484/>`_ argument (and return) type annotations.
  11. Four principal ways to do type checking are provided, each with its pros and cons:
  12. #. the ``check_argument_types()`` and ``check_return_type()`` functions:
  13. * debugger friendly (except when running with the pydev debugger with the C extension installed)
  14. * does not work reliably with dynamically defined type hints (e.g. in nested functions)
  15. #. the ``@typechecked`` decorator:
  16. * automatically type checks yields and sends of returned generators (regular and async)
  17. * adds an extra frame to the call stack for every call to a decorated function
  18. #. the stack profiler hook (``with TypeChecker('packagename'):``) (deprecated):
  19. * emits warnings instead of raising ``TypeError``
  20. * requires very few modifications to the code
  21. * multiple TypeCheckers can be stacked/nested
  22. * does not work reliably with dynamically defined type hints (e.g. in nested functions)
  23. * may cause problems with badly behaving debuggers or profilers
  24. * cannot distinguish between an exception being raised and a ``None`` being returned
  25. #. the import hook (``typeguard.importhook.install_import_hook()``):
  26. * automatically annotates classes and functions with ``@typechecked`` on import
  27. * no code changes required in target modules
  28. * requires imports of modules you need to check to be deferred until after the import hook has
  29. been installed
  30. * may clash with other import hooks
  31. See the documentation_ for further instructions.
  32. .. _documentation: https://typeguard.readthedocs.io/en/latest/