Skip to content

Latest commit

 

History

History
30 lines (19 loc) · 1017 Bytes

README.rst

File metadata and controls

30 lines (19 loc) · 1017 Bytes

python-autocast-decorator

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

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

from autocast import autocast

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

>>> my_function('3')
<type 'int'>

Contribute

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