Skip to content

Python library to automatically cast function arguments using decorator.

License

Notifications You must be signed in to change notification settings

ctgk/pyautocast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyautocast

Python library to automatically cast function arguments using decorator.

Install

pip install pyautocast

Usage

>>> from pyautocast import autocast
>>> @autocast(x=str)
... def func(x):
...     assert(isinstance(x, str))
...     return "arg 'x' in func() is " + x
...
>>> func(2)
"arg 'x' in func() is 2"
>>> func([1, 2, 3])
"arg 'x' in func() is [1, 2, 3]"
>>> from pyautocast import CustomCast
>>> mycast = CustomCast()
>>> mycast.add_cast_rule(int, tuple, lambda x: (x, x))
>>> @mycast.autocast(x=tuple)
... def func(x):
...     print(x)
>>> func(2)
(2, 2)
>>> func(-4.5)
Traceback (most recent call last):
...
TypeError: 'float' object is not iterable

About

Python library to automatically cast function arguments using decorator.

Resources

License

Stars

Watchers

Forks

Packages

No packages published