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 details)

Uploaded Source

File details

Details for the file pyautocast-0.1.1.tar.gz.

File metadata

  • Download URL: pyautocast-0.1.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

File hashes

Hashes for pyautocast-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3213cf5ce29eb6baeab6f1dbbea798794083a3343b157fee5994679c386e19f6
MD5 0ec6b86806721cb44b47fbafb1e1a0bb
BLAKE2b-256 5e45720a996fdcad8a295b73b86ad7eb60669dd834b418d758a793376f94239d

See more details on using hashes here.

Supported by

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