Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 1.46 KB

README.md

File metadata and controls

65 lines (49 loc) · 1.46 KB

python-type-valid

Python type valid Build passed Python type valid Code Coverage Maintainability

Python type validation decorator, validates input and output types

Installation

pip install type-valid

Usage

from type_valid import type_valid

@type_valid
def hello(name: str) -> str:
    return name

#valid
hello("Bob")

@type_valid
def hello_second(name: str) -> int:
    return name

#invalid output
hello_second("edds")

@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

TypeError: in method 'hello', Argument 'name' is not of type <class 'str'>, received <class 'int'>
TypeError: in method 'user', Argument 'name' is required
TypeError: in method 'hello_second', output 'edds' is not of type <class 'int'>, received <class 'str'>

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 ()
...