示例#1
0
    def _fix_eval_field_params(self):
        """Replace f-string field ID placeholders with the actual field
        expressions."""
        for node in ast.walk(self.res):
            if not (
                isinstance(node, ast.Call)
                and node.func.value.id == "__xonsh__"
                and node.func.attr == "eval_fstring_field"
                and len(node.args) > 0
            ):
                continue

            if PYTHON_VERSION_INFO > (3, 8):
                if isinstance(node.args[0], ast.Constant) and isinstance(
                    node.args[0].value, int
                ):
                    field = self.fields.pop(node.args[0].value, None)
                    if field is None:
                        continue
                    lineno = node.args[0].lineno
                    col_offset = node.args[0].col_offset
                    field_node = ast.Tuple(
                        elts=[
                            ast.Constant(
                                value=field[0], lineno=lineno, col_offset=col_offset
                            ),
                            ast.Constant(
                                value=field[1], lineno=lineno, col_offset=col_offset
                            ),
                        ],
                        ctx=ast.Load(),
                        lineno=lineno,
                        col_offset=col_offset,
                    )
                    node.args[0] = field_node
            elif isinstance(node.args[0], ast.Num):
                field = self.fields.pop(node.args[0].n, None)
                if field is None:
                    continue
                lineno = node.args[0].lineno
                col_offset = node.args[0].col_offset
                elts = [ast.Str(s=field[0], lineno=lineno, col_offset=col_offset)]
                if field[1] is not None:
                    elts.append(
                        ast.Str(s=field[1], lineno=lineno, col_offset=col_offset)
                    )
                else:
                    elts.append(
                        ast.NameConstant(
                            value=None, lineno=lineno, col_offset=col_offset
                        )
                    )
                field_node = ast.Tuple(
                    elts=elts, ctx=ast.Load(), lineno=lineno, col_offset=col_offset,
                )
                node.args[0] = field_node
示例#2
0
文件: v35.py 项目: zzp0/xonsh
 def p_atom_expr_await(self, p):
     """atom_expr : await_tok atom trailer_list_opt"""
     p0 = self.apply_trailers(p[2], p[3])
     p1 = p[1]
     p0 = ast.Await(value=p0, ctx=ast.Load(), lineno=p1.lineno,
                    col_offset=p1.lexpos)
     p[0] = p0