Skip to content

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

License

Notifications You must be signed in to change notification settings

guykisel/python-autocast-decorator

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages