def buildReturnNode(provider, node, source_ref): if provider.isExpressionClassBody() or provider.isCompiledPythonModule(): SyntaxErrors.raiseSyntaxError( "'return' outside function", source_ref.atColumnNumber(node.col_offset)) expression = buildNode(provider, node.value, source_ref, allow_none=True) if provider.isExpressionGeneratorObjectBody(): if expression is not None and python_version < 0x300: SyntaxErrors.raiseSyntaxError( "'return' with argument inside generator", source_ref.atColumnNumber(node.col_offset), ) if provider.isExpressionAsyncgenObjectBody(): if expression is not None: SyntaxErrors.raiseSyntaxError( "'return' with value in async generator", source_ref.atColumnNumber(node.col_offset), ) if (provider.isExpressionGeneratorObjectBody() or provider.isExpressionAsyncgenObjectBody()): if expression is None: expression = ExpressionConstantNoneRef(source_ref=source_ref) return StatementGeneratorReturn(expression=expression, source_ref=source_ref) else: return makeStatementReturn(expression=expression, source_ref=source_ref)
def buildReturnNode(provider, node, source_ref): if provider.isExpressionClassBody() or provider.isCompiledPythonModule(): SyntaxErrors.raiseSyntaxError( "'return' outside function", source_ref, None if python_version < 300 else (node.col_offset if provider.isCompiledPythonModule() else node.col_offset + 4)) expression = buildNode(provider, node.value, source_ref, allow_none=True) if provider.isExpressionGeneratorObjectBody(): if expression is not None and python_version < 330: SyntaxErrors.raiseSyntaxError( "'return' with argument inside generator", source_ref=source_ref, ) if expression is None: expression = ExpressionConstantRef(constant=None, source_ref=source_ref, user_provided=True) if provider.isExpressionGeneratorObjectBody(): return StatementGeneratorReturn(expression=expression, source_ref=source_ref) else: return StatementReturn(expression=expression, source_ref=source_ref)