当前位置: 首页>>代码示例>>Python>>正文


Python ast.expr方法代码示例

本文整理汇总了Python中ast.expr方法的典型用法代码示例。如果您正苦于以下问题:Python ast.expr方法的具体用法?Python ast.expr怎么用?Python ast.expr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ast的用法示例。


在下文中一共展示了ast.expr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def __init__(
            self,
            keys: t.List[ast.expr],
            values: t.List[ast.expr],
            ctx: t.Union[ast.Store, ast.Load],
            lineno=None,
            col_offset=None,
    ):
        super().__init__()
        self.keys = keys
        self.values = values
        self.ctx = ctx
        if lineno:
            self.lineno = lineno
        if col_offset:
            self.col_offset = col_offset 
开发者ID:Xython,项目名称:YAPyPy,代码行数:18,代码来源:extended_ast.py

示例2: visit_Hook

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def visit_Hook(self, node: parsing.Hook) -> ast.expr:
        """Generates python code calling a hook.

        self.evalHook('hookname', self.ruleNodes[-1])
        """
        return ast.Call(
            ast.Attribute(
                ast.Name('self', ast.Load()), 'evalHook', ast.Load()),
            [
                ast.Str(node.name),
                ast.Subscript(
                    ast.Attribute(
                        ast.Name('self', ast.Load()), 'ruleNodes', ast.Load()),
                    ast.Index(ast.UnaryOp(ast.USub(), ast.Num(1))),
                    ast.Load())],
            [],
            None,
            None) 
开发者ID:LionelAuroux,项目名称:pyrser,代码行数:20,代码来源:topython.py

示例3: visit_Rep0N

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def visit_Rep0N(self, node: parsing.Rep0N) -> [ast.stmt]:
        """Generates python code for a clause repeated 0 or more times.

        #If all clauses can be inlined
        while clause:
            pass

        while True:
            <code for the clause>
        """
        cl_ast = self.visit(node.pt)
        if isinstance(cl_ast, ast.expr):
            return [ast.While(cl_ast, [ast.Pass()], [])]
        self.in_loop += 1
        clause = self._clause(self.visit(node.pt))
        self.in_loop -= 1
        return [ast.While(ast.Name('True', ast.Load()), clause, [])] 
开发者ID:LionelAuroux,项目名称:pyrser,代码行数:19,代码来源:topython.py

示例4: _process_set_literal

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def _process_set_literal(
        tokens: List[Token],
        start: int,
        arg: ast.expr,
) -> None:
    if _is_wtf('set', tokens, start):
        return

    gen = isinstance(arg, ast.GeneratorExp)
    set_victims = _victims(tokens, start + 1, arg, gen=gen)

    del set_victims.starts[0]
    end_index = set_victims.ends.pop()

    tokens[end_index] = Token('OP', '}')
    for index in reversed(set_victims.starts + set_victims.ends):
        _remove_brace(tokens, index)
    tokens[start:start + 2] = [Token('OP', '{')] 
开发者ID:asottile,项目名称:pyupgrade,代码行数:20,代码来源:pyupgrade.py

示例5: _is_os_error_alias

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def _is_os_error_alias(self, node: Optional[ast.expr]) -> bool:
        return (
            isinstance(node, ast.Name) and
            node.id in self.OS_ERROR_ALIASES
        ) or (
            isinstance(node, ast.Name) and
            node.id == 'error' and
            (
                node.id in self._from_imports['mmap'] or
                node.id in self._from_imports['select'] or
                node.id in self._from_imports['socket']
            )
        ) or (
            isinstance(node, ast.Attribute) and
            isinstance(node.value, ast.Name) and
            node.value.id in self.OS_ERROR_ALIAS_MODULES and
            node.attr == 'error'
        ) 
开发者ID:asottile,项目名称:pyupgrade,代码行数:20,代码来源:pyupgrade.py

示例6: _replace_typed_class

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def _replace_typed_class(
        tokens: List[Token],
        i: int,
        call: ast.Call,
        types: Dict[str, ast.expr],
) -> None:
    if i > 0 and tokens[i - 1].name in {'INDENT', UNIMPORTANT_WS}:
        indent = f'{tokens[i - 1].src}{" " * 4}'
    else:
        indent = ' ' * 4

    # NT = NamedTuple("nt", [("a", int)])
    # ^i                                 ^end
    end = i + 1
    while end < len(tokens) and tokens[end].name != 'NEWLINE':
        end += 1

    attrs = '\n'.join(f'{indent}{k}: {_unparse(v)}' for k, v in types.items())
    src = f'class {tokens[i].src}({_unparse(call.func)}):\n{attrs}'
    tokens[i:end] = [Token('CODE', src)] 
开发者ID:asottile,项目名称:pyupgrade,代码行数:22,代码来源:pyupgrade.py

示例7: pop_format_context

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def pop_format_context(self, expl_expr: ast.expr) -> ast.Name:
        """Format the %-formatted string with current format context.

        The expl_expr should be an str ast.expr instance constructed from
        the %-placeholders created by .explanation_param().  This will
        add the required code to format said string to .expl_stmts and
        return the ast.Name instance of the formatted string.

        """
        current = self.stack.pop()
        if self.stack:
            self.explanation_specifiers = self.stack[-1]
        keys = [ast.Str(key) for key in current.keys()]
        format_dict = ast.Dict(keys, list(current.values()))
        form = ast.BinOp(expl_expr, ast.Mod(), format_dict)
        name = "@py_format" + str(next(self.variable_counter))
        if self.enable_assertion_pass_hook:
            self.format_variables.append(name)
        self.expl_stmts.append(ast.Assign([ast.Name(name, ast.Store())], form))
        return ast.Name(name, ast.Load()) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:22,代码来源:rewrite.py

示例8: getLineNo

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def getLineNo(self, node):
        lineno = 0
        if isinstance(node, (ast.stmt, ast.expr)):
            lineno = node.lineno
        return lineno 
开发者ID:myhdl,项目名称:myhdl,代码行数:7,代码来源:_misc.py

示例9: getVal

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def getVal(self, node):
        expr = ast.Expression()
        expr.body = node
        expr.lineno = node.lineno
        expr.col_offset = node.col_offset
        c = compile(expr, '<string>', 'eval')
        val = eval(c, self.tree.symdict, self.tree.vardict)
        # val = eval(_unparse(node), self.tree.symdict, self.tree.vardict)
        return val 
开发者ID:myhdl,项目名称:myhdl,代码行数:11,代码来源:_misc.py

示例10: _is_ast_expr

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def _is_ast_expr(node):
    return isinstance(node, ast.expr) 
开发者ID:pytest-dev,项目名称:py,代码行数:4,代码来源:_assertionnew.py

示例11: visit_Expr

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def visit_Expr(self, expr):
        return self.visit(expr.value) 
开发者ID:pytest-dev,项目名称:py,代码行数:4,代码来源:_assertionnew.py

示例12: _parse_expr

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def _parse_expr(token: Tokenizer):
    expr = ast.parse(token.value).body[0].value
    expr.lineno = token.lineno
    expr.col_offset = token.colno
    return expr 
开发者ID:Xython,项目名称:YAPyPy,代码行数:7,代码来源:helper.py

示例13: check_call_args

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def check_call_args(loc, seq: t.List[ast.expr]):
    in_keyword_section = False
    for each in seq:
        if isinstance(each, ast.keyword):
            in_keyword_section = True
        elif in_keyword_section and not isinstance(each, ast.Starred):
            error = SyntaxError()
            error.lineno = loc['lineno']
            error.msg = 'non-keyword argument follows keyword argument'
            raise error
    return seq 
开发者ID:Xython,项目名称:YAPyPy,代码行数:13,代码来源:helper.py

示例14: visit_Module

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def visit_Module(self, node, **kwargs):
        if len(node.body) != 1:
            raise SyntaxError('only a single expression is allowed')
        expr = node.body[0]
        return self.visit(expr, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:expr.py

示例15: __init__

# 需要导入模块: import ast [as 别名]
# 或者: from ast import expr [as 别名]
def __init__(self, expr, engine='numexpr', parser='pandas', env=None,
                 truediv=True, level=0):
        self.expr = expr
        self.env = env or Scope(level=level + 1)
        self.engine = engine
        self.parser = parser
        self.env.scope['truediv'] = truediv
        self._visitor = _parsers[parser](self.env, self.engine, self.parser)
        self.terms = self.parse() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:expr.py


注:本文中的ast.expr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。