Giter Site home page Giter Site logo

typeguard's Introduction

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.

typeguard's People

Contributors

agronholm avatar pre-commit-ci[bot] avatar wbolster avatar epronovost avatar vthemelis avatar prescod avatar supersergiy avatar rfrowe avatar kstauffer avatar mtelka avatar pirate avatar hauntsaninja avatar tolker-ku avatar tfiers avatar williamlw999-fb avatar fefe982 avatar biolds avatar epenet avatar jacobpbrugh avatar russok avatar kelseyfrancis avatar jtbeach avatar jwilk avatar cotsog avatar danie-1 avatar dalejung avatar deathowl avatar cjolowicz avatar reinhrst avatar flexatone avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.