(self, node: ast.FunctionDef)
Using bfs find all `return` statements in function.
Using bfs find all `return` statements in function.
Using bfs find all return statements in function .
def _find_generator_returns(self, node: ast.FunctionDef) \
            -> List[Tuple[ast.stmt, ast.Return]]:
        """Using bfs find all `return` statements in function."""
        to_check = [(node, x) for x in node.body]  # type: ignore
        returns = []
        has_yield = False
        while to_check:
            parent, current = to_check.pop()

            if isinstance(current, ast.FunctionDef):
                continue
            elif hasattr(current, 'value'):
                to_check.append((current, current.value))  # type: ignore
            elif hasattr(current, 'body') and isinstance(current.body, list):  # type: ignore
                to_check.extend([(parent, x) for x in current.body])  # type: ignore

            if isinstance(current, ast.Yield) or isinstance(current, ast.YieldFrom):
                has_yield = True

            if isinstance(current, ast.Return) and current.value is not None:
                returns.append((parent, current))

        if has_yield:
            return returns  # type: ignore
        else:
            return []
def _find_generator_returns ( self , node : ast . FunctionDef ) -> List [ Tuple [ ast . stmt , ast . Return ] ] : to_check = [ ( node , x ) for x in node . body ] # type: ignore returns = [ ] has_yield = False while to_check : parent , current = to_check . pop ( ) if isinstance ( current , ast . FunctionDef ) : continue elif hasattr ( current , 'value' ) : to_check . append ( ( current , current . value ) ) # type: ignore elif hasattr ( current , 'body' ) and isinstance ( current . body , list ) : # type: ignore to_check . extend ( [ ( parent , x ) for x in current . body ] ) # type: ignore if isinstance ( current , ast . Yield ) or isinstance ( current , ast . YieldFrom ) : has_yield = True if isinstance ( current , ast . Return ) and current . value is not None : returns . append ( ( parent , current ) ) if has_yield : return returns # type: ignore else : return [ ]