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
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
argreq-0.2.0.tar.gz
(7.4 kB
view hashes)
Built Distribution
argreq-0.2.0-py3-none-any.whl
(7.7 kB
view hashes)