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
Download 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.5.tar.gz
(2.3 kB
view details)
Built Distribution
File details
Details for the file type_valid-0.1.5.tar.gz
.
File metadata
- Download URL: type_valid-0.1.5.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93588077e926a87842e6bcb023884bc71ee2e728914f29395ec2dcfc569da885 |
|
MD5 | 0d4babb3c9d2aa80b138cfae646b23b3 |
|
BLAKE2b-256 | b658fec6cc4917c52ba52ec45de2e1760195263e55331668a7046bc4b6f53c1e |
File details
Details for the file type_valid-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: type_valid-0.1.5-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96b8454bf125f22cebb172d641bdea614683853247b57ea9581da3daf0200b22 |
|
MD5 | 9c6254a81d04a491b9cc51005d4be9c3 |
|
BLAKE2b-256 | dca091fccd3d028d9c460b5af0f481550468d8a7a1193ecd16bd7a4d8f1a44d0 |