A python function parameter and return type-checking decorator
Project description
# Complaince
A python function parameter and return type-checking decorator
Both the parameters types and return type(optional to check for return type)
can be done using a single decorator.
Each parameter can have multiple possible types , mentioned in a tuple
Examples
========
When plainly checking parameter types
```python
@param_check((int,float),(int,float))
def myfunc(a, b):
```
This indicates the parameters a,b can be either int or float
```python
@param_check((int,),(int,))
def myfunc(a, b):
```
In this case both a and b have to be int only (tuple definition is a must )
There is are two optional parameters:
1. level - Key-Value pair indicates warning message(continue execution after type error) or throw an exception(essentially
terminating the execution flow) (0 - warning , 1 - exception error) Default
is warning i.e 0
2. ret - Key-Value pair indicating possible return types, in this case too
value is a tuple
```python
@param_check((int,float),(int,float), level = 1, ret = (int,float))
def myfunc(a, b)
```
In the above example we will throw an exception if the parameters, return value do not match
required types. Return value can be either an in or float
Compatability
=============
Requires python 2.6 or higher
Works with python 3.0 and higher
A python function parameter and return type-checking decorator
Both the parameters types and return type(optional to check for return type)
can be done using a single decorator.
Each parameter can have multiple possible types , mentioned in a tuple
Examples
========
When plainly checking parameter types
```python
@param_check((int,float),(int,float))
def myfunc(a, b):
```
This indicates the parameters a,b can be either int or float
```python
@param_check((int,),(int,))
def myfunc(a, b):
```
In this case both a and b have to be int only (tuple definition is a must )
There is are two optional parameters:
1. level - Key-Value pair indicates warning message(continue execution after type error) or throw an exception(essentially
terminating the execution flow) (0 - warning , 1 - exception error) Default
is warning i.e 0
2. ret - Key-Value pair indicating possible return types, in this case too
value is a tuple
```python
@param_check((int,float),(int,float), level = 1, ret = (int,float))
def myfunc(a, b)
```
In the above example we will throw an exception if the parameters, return value do not match
required types. Return value can be either an in or float
Compatability
=============
Requires python 2.6 or higher
Works with python 3.0 and higher
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for complaince-1.0.1.0b1.dev1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4644e0ab0e09dc5466f94bc29a2a5bf460604a0d0ee8e96a26ae4352810c152e |
|
MD5 | 8561f35c3ab51d43b3e08aeb352318a9 |
|
BLAKE2b-256 | ee8debdc744f2e07e3e2ab401f3abdcccac44bf6a41aca29786b17f111f3f939 |