Skip to main content

Run-time type checker for Python

Project description

Build Status Code Coverage Documentation

This library provides run-time type checking for functions defined with PEP 484 argument (and return) type annotations, and any arbitrary objects. It can be used together with static type checkers as an additional layer of type safety, to catch type violations that could only be detected at run time.

Two principal ways to do type checking are provided:

  1. The check_type function:

    • like isinstance(), but supports arbitrary type annotations (within limits)

    • can be used as a cast() replacement, but with actual checking of the value

  2. Code instrumentation:

    • entire modules, or individual functions (via @typechecked) are recompiled, with type checking code injected into them

    • automatically checks function arguments, return values and assignments to annotated local variables

    • for generator functions (regular and async), checks yield and send values

    • requires the original source code of the instrumented module(s) to be accessible

Two options are provided for code instrumentation:

  1. the @typechecked function:

    • can be applied to functions individually

  2. the import hook (typeguard.install_import_hook()):

    • automatically instruments targeted modules on import

    • no manual code changes required in the target modules

    • requires the import hook to be installed before the targeted modules are imported

    • may clash with other import hooks

See the documentation for further information.

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-4.4.4.tar.gz (75.2 kB view details)

Uploaded Source

Built Distribution

typeguard-4.4.4-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typeguard-4.4.4.tar.gz
  • Upload date:
  • Size: 75.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for typeguard-4.4.4.tar.gz
Algorithm Hash digest
SHA256 3a7fd2dffb705d4d0efaed4306a704c89b9dee850b688f060a8b1615a79e5f74
MD5 4f97177b802372a70bb571b2aff09313
BLAKE2b-256 c76871c1a15b5f65f40e91b65da23b8224dad41349894535a97f63a52e462196

See more details on using hashes here.

Provenance

The following attestation bundles were made for typeguard-4.4.4.tar.gz:

Publisher: publish.yml on agronholm/typeguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: typeguard-4.4.4-py3-none-any.whl
  • Upload date:
  • Size: 34.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for typeguard-4.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b5f562281b6bfa1f5492470464730ef001646128b180769880468bd84b68b09e
MD5 9d374d1cf315bfe0dad9eb480882f632
BLAKE2b-256 1ba9e3aee762739c1d7528da1c3e06d518503f8b6c439c35549b53735ba52ead

See more details on using hashes here.

Provenance

The following attestation bundles were made for typeguard-4.4.4-py3-none-any.whl:

Publisher: publish.yml on agronholm/typeguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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