Skip to main content

Automatic function arguments casting

Project description

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

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

pyautocast-0.1.1.tar.gz (2.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page