Skip to main content

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

Project description

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+

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

return-result-1.1.0.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

return_result-1.1.0-py3-none-any.whl (2.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page