Skip to main content

Add requirements to function arguments using simple and elegant decorators

Project description

Add requirements to function arguments using simple and elegant decorators

Installation:

pip install argreq

Examples

from argreq import argument, requirement

@argument('a', '>10', type=int)
def int_grater_than_10(a):
    '''If a is smaller than 10, function raises 'NotValidArgumentError' '''
    print(f'a ({a}) is int and larger then 10!')

@argument('a', ('>10', '<20'), type=int)
def other_func(a):
    '''Check if a is grater than 10 AND smaller than 20'''
    print(f'a {a} is int and between 10 and 20')

@argument('a', '10<{}<20', type=int)
def prettier_other_func(a):
    '''Same as above but in a single requirement'''
    print(f'a ({a}) is int and between 10 and 20 and prettier ;)')

@argument('a','>0')
@argument('b','>0')
def div(a,b):
    '''Check if both a and b positive'''
    print(f'{a}/{b}={a/b}')

@argument('d', '"a" in {}', type=dict)
def dict_func(d):
    '''Check if d has the key 'a' '''
    print(f'd ({d}) has "a" in it')

@requirement('{a}>{b}>0')
def a_grater_than_b_and_positives(a, b):
    '''Check if a is grater then b and both positives'''
    print(f'{a} > {b}')

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

argreq-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

argreq-0.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file argreq-0.2.0.tar.gz.

File metadata

  • Download URL: argreq-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for argreq-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9da1fee24525436f0bc1e8a6a56c868537f4e44e954e094287e32d6e6dd35680
MD5 e7f65f363731811d63e12ac2f87792bb
BLAKE2b-256 1fd032ff76f9d2e7bf6a84fa81e336ccd12fa8c48b501fe9b536c10a6181994a

See more details on using hashes here.

File details

Details for the file argreq-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: argreq-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for argreq-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8b344916c73e0e522bb297e58c0cedc7920e7caf295a709576fb049d299301c
MD5 0f9e448ca7f6b6364cb3fdcb48897c7d
BLAKE2b-256 93963081b97322eb4b82fdf223082e38091af8723f0c629692038c9280491c1a

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