def build_Print(ctx, stmt): r = ctx.make_range(stmt.lineno, stmt.col_offset, stmt.col_offset + len("print")) if stmt.dest: raise NotSupportedError( r, "print statements with non-default destinations aren't supported" ) args = [build_expr(ctx, val) for val in stmt.values] return ExprStmt(Apply(Var(Ident(r, "print")), args, []))
def build_Call(ctx, expr): func = build_expr(ctx, expr.func) args = [build_expr(ctx, py_arg) for py_arg in expr.args] if hasattr(expr, 'starargs') and expr.starargs: stararg_expr = build_expr(ctx, expr.starargs) args += [Starred(stararg_expr.range(), stararg_expr)] kwargs = [] for kw in expr.keywords: kw_expr = build_expr(ctx, kw.value) # XXX: we could do a better job at figuring out the range for the name here if not kw.arg: raise NotSupportedError(kw_expr.range(), 'keyword-arg expansion is not supported') kwargs.append(Attribute(Ident(kw_expr.range(), kw.arg), kw_expr)) return Apply(func, args, kwargs)
def build_JoinedStr(ctx, expr): s = '' args = [] for value in expr.values: r = ctx.make_range(value.lineno, value.col_offset, value.col_offset + 1) if isinstance(value, ast.FormattedValue): if value.conversion != -1: raise NotSupportedError(r, 'Don\'t support conversion in JoinedStr') if value.format_spec is not None: raise NotSupportedError(r, 'Don\'t support formatting in JoinedStr') s += '{}' args.append(build_expr(ctx, value.value)) elif isinstance(value, ast.Str): s += value.s else: raise NotSupportedError(r, 'Unsupported value in JoinedStr') r = ctx.make_range(expr.lineno, expr.col_offset, expr.col_offset + 1) return Apply(Select(StringLiteral(r, s), Ident(r, 'format')), args, [])