Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Run-time type checker for Python

License

NotificationsYou must be signed in to change notification settings

agronholm/typeguard

Repository files navigation

Build StatusCode CoverageDocumentation

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

Two principal ways to do type checking are provided:

  1. Thecheck_type function:
    • likeisinstance(), but supports arbitrary type annotations (within limits)
    • can be used as acast() replacement, but with actual checking of the value
  2. Code instrumentation:
    • entire modules, or individual functions (via@typechecked) are recompiled, withtype checking code injected into them
    • automatically checks function arguments, return values and assignments to annotatedlocal 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 thedocumentation for further information.


[8]ページ先頭

©2009-2025 Movatter.jp