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.
- Host: GitHub
- URL: https://github.com/guykisel/python-autocast-decorator
- Owner: guykisel
- License: mit
- Created: 2014-11-13T21:51:55.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-14T17:35:06.000Z (about 1 year ago)
- Last Synced: 2025-03-10T23:36:44.626Z (9 months ago)
- Language: Python
- Size: 8.79 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
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.