Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/not-raspberry/returns
A decorator to create namedtuples for return values
https://github.com/not-raspberry/returns
Last synced: 22 days ago
JSON representation
A decorator to create namedtuples for return values
- Host: GitHub
- URL: https://github.com/not-raspberry/returns
- Owner: not-raspberry
- Created: 2015-09-09T21:12:20.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-11T17:46:41.000Z (about 9 years ago)
- Last Synced: 2023-03-01T19:50:56.876Z (over 1 year ago)
- Language: Python
- Size: 148 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
returns
=======
.. image:: https://travis-ci.org/not-raspberry/returns.svg?branch=master
:target: https://travis-ci.org/not-raspberry/returns
.. image:: https://coveralls.io/repos/not-raspberry/returns/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/not-raspberry/returns?branch=masterWhat is it?
-----------
The easiest way to return a value of a known type, with named fields accessible via attributes.For whom?
---------
For people too lazy to create namedtuples by themselves.Examples
--------
.. code:: pythonimport returns
# Name generated from function name:
@returns.namedtuple('monkeys', 'snakes')
def get_monkeys_and_snakes():
return 'A lot!', 'Even more!'get_monkeys_and_snakes() # -> GetMonkeysAndSnakes(monkeys='A lot!', snakes='Even more!')
# With a custom name:
@returns.namedtuple('hyenas', 'lions', name='HyaenaeEtLeones')
def get_hyenas_and_lions():
return 'A herd.', 42get_hyenas_and_lions() # -> HyaenaeEtLeones(hyenas='A herd.', lions=42)
Trivia
------
As every library that does almost nothing, this one is also weirdly named. ``returns`` is not even a
noun. It looks like a keyword. Add insult to injury, the name ``returns.namedtuple`` may be mistaken
with the ``namedtuple`` from ``collections``.But c'mon! It reads like a sentence! ``@returns.namedtuple`` - it's like 'returns namedtuple',
right? That's what cool-kid programming is all about!