Skip to main content

Run-time type checker for Python

Project description

Build Status Code Coverage https://readthedocs.org/projects/typeguard/badge/?version=latest

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

Four 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 stack profiler hook (with TypeChecker('packagename'):) (deprecated):

    • emits warnings instead of raising TypeError

    • requires very few modifications to the code

    • multiple TypeCheckers can be stacked/nested

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

    • may cause problems with badly behaving debuggers or profilers

    • cannot distinguish between an exception being raised and a None being returned

  4. 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

See the documentation for further instructions.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typeguard-2.11.1.tar.gz (38.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typeguard-2.11.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file typeguard-2.11.1.tar.gz.

File metadata

  • Download URL: typeguard-2.11.1.tar.gz
  • Upload date:
  • Size: 38.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for typeguard-2.11.1.tar.gz
Algorithm Hash digest
SHA256 33243c1cbfcb9736a06c6db22dd08876b5f297e6344aa272a2862c0f8e669f64
MD5 a9f398fcd7ce1541257a1f6f8ee4945d
BLAKE2b-256 3f592afc3814b33e688b80cd9017b8f1318b105a3df9080d8bbda82a726907f0

See more details on using hashes here.

File details

Details for the file typeguard-2.11.1-py3-none-any.whl.

File metadata

  • Download URL: typeguard-2.11.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for typeguard-2.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c62706201ec6c14962162fa67d70bd2762753247533d70ff2442e5ac08f94fa2
MD5 a5eb4ce3fa6dd1aceab6d9a6020c84a4
BLAKE2b-256 500f788beaef5b73aacaae1eea11b1165fd4dec0a4c600fb2cb1611f55caf4ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page