An open API service indexing awesome lists of open source software.

https://github.com/guykisel/python-autocast-decorator

Decorator for automatically casting string inputs to their most likely Python data types.
https://github.com/guykisel/python-autocast-decorator

Last synced: 9 months ago
JSON representation

Decorator for automatically casting string inputs to their most likely Python data types.

Awesome Lists containing this project

README

          

python-autocast-decorator
=========================

.. image:: https://travis-ci.org/guykisel/python-autocast-decorator.svg?branch=master
:target: https://travis-ci.org/guykisel/python-autocast-decorator/builds

Decorator for automatically casting string inputs to their most likely Python data types.

This implementation runs ``ast.literal_eval()`` on all inputs. This is simple and reliable, but fairly slow, and therefore probably inappropriate for code that must run fast.

This decorator uses `wrapt `__ to enable signature-preserving decoration.

For more discussion, see https://stackoverflow.com/questions/7019283/automatically-type-cast-parameters-in-python

.. code:: python

from autocast import autocast

@autocast
def my_function(arg):
print(type(arg))

>>> my_function('3')

Contribute
----------

If you like this module, please contribute! I welcome patches,
documentation, issues, ideas, and so on.