Skip to content

MichaelKim0407/returns-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 ...