Skip to content

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

Notifications You must be signed in to change notification settings

BolunThompson/return-result

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI version Python versions Black codestyle

return-result

I am not maintaining this; it my not work or have bugs on the latest version of python.

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+

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages