returns-decorator

@returns(TYPE)


Keywords
python
License
MIT
Install
pip install returns-decorator==1.1

Documentation

returns-decorator

Build Status Coverage Status

Installation

pip install returns-decorator

Usage

from returns import returns

@returns(int)
def func(...):
    ...

The return value will be converted into int before returning.

It's the equivalent of:

return int(return_value)

On every return statement.


It's most useful to convert a generator function into a tuple/list/set/dict.

@returns(tuple)
def generator_func():
    yield ...

Doing this has a better performance than list.append.


When None is a possible return value, you can pass allow_none=True into the decorator.

@returns(int, allow_none=True)
def func(...):
    if ...:
        return None
    return ...