當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。