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


Python _ast.Expr方法代码示例

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


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

示例1: run

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def run(self, node, input_state):
    result_state = input_state.copy()
    block = node.data

    constraints = self.cfg.block_constraints

    for stmt in block.statements:
      native = stmt.native
      if isinstance(native, _ast.Assign) or isinstance(native, _ast.AugAssign):
        self.transfer_assign(result_state, native, stmt.start_bytecode_index)

      elif isinstance(native, _ast.Expr):
        value = native.value
        logger.debug("Stmt kind: %s", type(value))
        if isinstance(value, _ast.Call):
          self.transfer_call(result_state, native, stmt.start_bytecode_index)
      else:
        logger.error("Unknown stmt: %s", dump_native_ast(native))

    return result_state


  # Assign: a <- b 
开发者ID:neuroo,项目名称:equip,代码行数:25,代码来源:types.py

示例2: visit_expr

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def visit_expr(self, node, parent):
        """visit a Expr node by returning a fresh instance of it"""
        newnode = nodes.Expr(node.lineno, node.col_offset, parent)
        newnode.postinit(self.visit(node.value, newnode))
        return newnode 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:7,代码来源:rebuilder.py

示例3: _get_doc

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def _get_doc(node):
    try:
        if isinstance(node.body[0], _ast.Expr) and isinstance(node.body[0].value, _ast.Str):
            doc = node.body[0].value.s
            node.body = node.body[1:]
            return node, doc
    except IndexError:
        pass # ast built from scratch
    return node, None 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:11,代码来源:rebuilder.py

示例4: to_python_statment

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def to_python_statment(bytecode):
    i = len(bytecode) - 1
    while i >= 0:
      index, lineno, op, arg, cflow_in, code_object = bytecode[i]
      prev_op = bytecode[i - 1][2] if i > 1 else -1
      if op in (PRINT_ITEM, PRINT_NEWLINE, PRINT_ITEM_TO, PRINT_NEWLINE_TO):
        _, stmt = Statement.to_print_statement(i, op, bytecode)
        return stmt
      elif op in CALL_OPCODES:
        _, call = Statement.make_call(i, bytecode)
        return _ast.Expr(call)
      elif op == COMPARE_OP:
        _, cmp_expr = Statement.make_comparator(i, bytecode)
        return _ast.Expr(cmp_expr)
      elif op in STORE_OPCODES and prev_op not in (MAKE_FUNCTION, BUILD_CLASS):
        _, store_stmt = Statement.make_assign(i, bytecode)
        return store_stmt
      elif op in STORE_SLICE_OPCODES or op in DELETE_SLICE_OPCODES:
        _, store_stmt = Statement.make_store_delete_slice(i, bytecode)
        return store_stmt
      elif op in DELETE_OPCODES:
        _, store_stmt = Statement.make_delete(i, bytecode)
        return store_stmt
      else:
        logger.debug("Unhandled >> STMT:\n%s", show_bytecode(bytecode))
      i -= 1
    return None 
开发者ID:neuroo,项目名称:equip,代码行数:29,代码来源:stmt.py

示例5: visit_expr

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def visit_expr(self, node: _ast.Expr):  # value,
        return self._run(node.value) 
开发者ID:item4,项目名称:yui,代码行数:4,代码来源:calc.py

示例6: isDocstring

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def isDocstring(self, node):
        """
        Determine if the given node is a docstring, as long as it is at the
        correct place in the node tree.
        """
        return isinstance(node, ast.Str) or (isinstance(node, ast.Expr) and
                                             isinstance(node.value, ast.Str)) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:9,代码来源:checker.py

示例7: getDocstring

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def getDocstring(self, node):
        if isinstance(node, ast.Expr):
            node = node.value
        if not isinstance(node, ast.Str):
            return (None, None)

        if PYPY:
            doctest_lineno = node.lineno - 1
        else:
            # Computed incorrectly if the docstring has backslash
            doctest_lineno = node.lineno - node.s.count('\n') - 1

        return (node.s, doctest_lineno) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:15,代码来源:checker.py

示例8: parse_function

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def parse_function(node):
    old_style = None
    new_style = None
    output = None
    setup = []
    setup_done = False
    title, details = parse_docstring(ast.get_docstring(node, clean=True))
    name = node.name[5:] if node.name.startswith('test_') else node.name

    for n in node.body:
        # Ignore the docstring
        if isinstance(n, _ast.Expr) and isinstance(n.value, _ast.Str):
            continue
        if isinstance(n, _ast.Assign) and n.targets[0].id == 'old_result':
            setup_done = True
            old_style = unparse(n.value, strip=True)
        if isinstance(n, _ast.Assign) and n.targets[0].id == 'new_result':
            setup_done = True
            new_style = unparse(n.value, strip=True)
        if isinstance(n, _ast.Assert) and isinstance(
                n.test.comparators[0], _ast.Str):
            setup_done = True
            output = n.test.comparators[0].s
        if not setup_done:
            setup.append(n)

    if setup:
        setup = unparse(setup, strip=True)

    return Example(
        name,
        title,
        details,
        setup or "",
        old_style or "",
        new_style or "",
        output or ""
    ) 
开发者ID:ulope,项目名称:pyformat.info,代码行数:40,代码来源:main.py

示例9: getDocstring

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Expr [as 别名]
def getDocstring(self, node):
        if isinstance(node, ast.Expr):
            node = node.value
        if not isinstance(node, ast.Str):
            return (None, None)
        # Computed incorrectly if the docstring has backslash
        doctest_lineno = node.lineno - node.s.count('\n') - 1
        return (node.s, doctest_lineno) 
开发者ID:QQuick,项目名称:Transcrypt,代码行数:10,代码来源:checker.py


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