Python Type validator with decorators
Project description
# python-type-valid
[![Python type valid Build passed](https://travis-ci.org/edmhs/python-type-valid.svg?branch=master)](https://travis-ci.org/edmhs/python-type-valid)
[![Python type valid Code Coverage](https://codecov.io/gh/codecov/example-python/branch/master/graph/badge.svg)](https://codecov.io/gh/edmhs/python-type-valid)
[![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/edmhs/python-type-valid)
Python type validation decorator, validates input and output types
### Installation
~~~sh
pip install type-valid
~~~
### Usage
~~~python
from type_valid import type_valid
@type_valid
def hello(name: str) -> str:
return name
#valid
hello("Bob")
#invalid
hello(1)
@type_valid
def user(name: str, age: int, salary: float) -> str:
return name+str(age)+str(salary)
#valid
user(name="Bob", age=25, salary=1000.00)
~~~
### Raises TypeError
~~~sh
TypeError: in method 'hello', Argument 'name' is not of type <class 'str'>, received <class 'int'>
~~~
### Todo:
* Validate input DONE
* Validate Output DONE
* Validate input **kwargs ?
* Validate mandatory **kwargs ?
* Multiple types ?
### Types examples
~~~
str ""
int 4
float 10.5
list []
tuple ()
...
~~~
[![Python type valid Build passed](https://travis-ci.org/edmhs/python-type-valid.svg?branch=master)](https://travis-ci.org/edmhs/python-type-valid)
[![Python type valid Code Coverage](https://codecov.io/gh/codecov/example-python/branch/master/graph/badge.svg)](https://codecov.io/gh/edmhs/python-type-valid)
[![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/edmhs/python-type-valid)
Python type validation decorator, validates input and output types
### Installation
~~~sh
pip install type-valid
~~~
### Usage
~~~python
from type_valid import type_valid
@type_valid
def hello(name: str) -> str:
return name
#valid
hello("Bob")
#invalid
hello(1)
@type_valid
def user(name: str, age: int, salary: float) -> str:
return name+str(age)+str(salary)
#valid
user(name="Bob", age=25, salary=1000.00)
~~~
### Raises TypeError
~~~sh
TypeError: in method 'hello', Argument 'name' is not of type <class 'str'>, received <class 'int'>
~~~
### Todo:
* Validate input DONE
* Validate Output DONE
* Validate input **kwargs ?
* Validate mandatory **kwargs ?
* Multiple types ?
### Types examples
~~~
str ""
int 4
float 10.5
list []
tuple ()
...
~~~
Project details
NoneDownload files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
type_valid-0.1.4.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for type_valid-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf4bf8bb8752477bc6171f1b5a3a6c7e2a1a10ead28b095ecf4423944d82961d |
|
MD5 | c8d00ba9b77be4f303d41279c8682808 |
|
BLAKE2b-256 | 12c7a694bd41bec5cb09c725f1f123c7b937829950184e4caa2214946a54abc5 |