Skip to main content

utility for checking that call args have the expected types and all required args are provided

Project description

Arg Check

A Python utility for checking that call args have the expected types and all required args are provided.

Works only with Python 3.7 (fixing that soon)

Installation

pip install arg-check

Usage

This library uses simple decorators.

Argument Type Checking

@enforce_arg_types
def foobar(a: int, b: str):
    ...
  • Type checking is performed via the annotations. If an argument does not have an annotation, type checking is skipped just for that argument.
  • If an argument is a collection, all items in the collection are checked.
  • Can handle Union and Optional

Required Arguments

@required_args("a", "b")
def foobar(a, b, c=None):
    ...
  • Tests the given arguments and raises a ValueError if the value is either None or an empty string
  • To make all arguments required, use @required_args without parenthesis

All checks in one decorator

@strict_args
def foobar(a: int, b: str):
    ...
  • All arguments are type checked
  • All arguments are required

Project details


Download files

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

Source Distribution

argument-checks-0.1.1.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

argument_checks-0.1.1-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

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