return-result

This defines a decorator that causes the 'result' variable to be returned when there is no explicit return


Keywords
return, result, variable, nim
Install
pip install return-result==1.1.0

Documentation

PyPI version Python versions Black codestyle

return-result

This defines a decorator that causes the variable result to be automatically returned from a function when there is no return statement.

This works by getting the source code of the decorated function, so this won't work in the CPython REPL. It does work in IPython however.

Inspired by the Nim feature that does the same thing.

Example

>>> from return_result import return_result
>>> @return_result
... def test():
...     result = "Works!"
>>> test()
'Works!'

Requirements

Python 3.6+