(callable)
return _generator_callbacks_cache[callable]
Returns True if a callable is a generator function which includes a
    'return' statement with a value different than None, False otherwise
Returns True if a callable is a generator function which includes a
    'return' statement with a value different than None, False otherwise
Returns True if a callable is a generator function which includes a return statement with a value different than None False otherwise
def is_generator_with_return_value(callable):
    """
    Returns True if a callable is a generator function which includes a
    'return' statement with a value different than None, False otherwise
    """
    if callable in _generator_callbacks_cache:
        return _generator_callbacks_cache[callable]

    def returns_none(return_node):
        value = return_node.value
        return value is None or isinstance(value, ast.NameConstant) and value.value is None

    if inspect.isgeneratorfunction(callable):
        code = re.sub(r"^[\t ]+", "", inspect.getsource(callable))
        tree = ast.parse(code)
        for node in walk_callable(tree):
            if isinstance(node, ast.Return) and not returns_none(node):
                _generator_callbacks_cache[callable] = True
                return _generator_callbacks_cache[callable]

    _generator_callbacks_cache[callable] = False
    return _generator_callbacks_cache[callable]
def is_generator_with_return_value ( callable ) : if callable in _generator_callbacks_cache : return _generator_callbacks_cache [ callable ] def returns_none ( return_node ) : value = return_node . value return value is None or isinstance ( value , ast . NameConstant ) and value . value is None if inspect . isgeneratorfunction ( callable ) : code = re . sub ( r"^[\t ]+" , "" , inspect . getsource ( callable ) ) tree = ast . parse ( code ) for node in walk_callable ( tree ) : if isinstance ( node , ast . Return ) and not returns_none ( node ) : _generator_callbacks_cache [ callable ] = True return _generator_callbacks_cache [ callable ] _generator_callbacks_cache [ callable ] = False return _generator_callbacks_cache [ callable ]