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


Python _ast.AugAssign方法代码示例

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


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

示例1: run

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import AugAssign [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_augassign

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import AugAssign [as 别名]
def visit_augassign(self, node: _ast.AugAssign):  # target, op, value
        value = self._run(node.value)
        target = node.target
        target_cls = target.__class__
        op_cls = node.op.__class__

        if target_cls == _ast.Name:
            target_id = target.id  # type: ignore
            self.symbol_table[target_id] = BINOP_TABLE[op_cls](
                self.symbol_table[target_id], value,
            )
        elif target_cls == _ast.Subscript:
            sym = self._run(target.value)  # type: ignore
            xslice = self._run(target.slice)  # type: ignore
            if isinstance(target.slice, _ast.Index):  # type: ignore
                sym[xslice] = BINOP_TABLE[op_cls](sym[xslice], value,)
            else:
                raise BadSyntax('This assign method is not allowed')
        else:
            raise BadSyntax('This assign method is not allowed')
        return 
开发者ID:item4,项目名称:yui,代码行数:23,代码来源:calc.py

示例3: run

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

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

    return result_state 
开发者ID:neuroo,项目名称:equip,代码行数:16,代码来源:defs.py

示例4: __init__

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import AugAssign [as 别名]
def __init__(self, name, source, scope):
        if '__all__' in scope and isinstance(source, ast.AugAssign):
            self.names = list(scope['__all__'].names)
        else:
            self.names = []
        if isinstance(source.value, (ast.List, ast.Tuple)):
            for node in source.value.elts:
                if isinstance(node, ast.Str):
                    self.names.append(node.s)
        super(ExportBinding, self).__init__(name, source) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:12,代码来源:checker.py

示例5: make_assign

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import AugAssign [as 别名]
def make_assign(i, bytecode):
    op = bytecode[i][2]
    if op == STORE_SUBSCR:
      return Statement.make_subscript(i, bytecode)

    prev_op = bytecode[i - 1][2] if i > 0 else -1

    if prev_op in INPLACE_OPCODES:
      in_cls = Statement.INPLACE_OPERATORS[prev_op]
      i -= 1
      i, rhs = Statement.make_expr(i - 1, bytecode, context=_ast.AugStore())
      i, lhs = Statement.make_expr(i - 1, bytecode, context=_ast.AugLoad())
      return i, _ast.AugAssign(lhs, in_cls(), rhs)
    else:
      # We can either have multiple assignments: a = b = c = 1
      # or unpacked sequences: a, b = 1, foo()
      # the compiler does some optimization so that: a, b = c, d
      # does not rely on UNPACK_SEQUENCE, but a ROT_TWO (or ROT_THREE & ROT_TWO for 3 elements).
      # This happens for 2 or 3 elements to unpack
      targets = []
      value = None
      has_unpack, has_ROT_2_3, has_multiple = False, False, 0
      num_unpack = -1
      j = i
      while j >= 0:
        op = bytecode[j][2]
        if op == UNPACK_SEQUENCE:
          has_unpack = True
          num_unpack = bytecode[j][3]
          break
        elif op in (ROT_TWO, ROT_THREE):
          has_ROT_2_3 = True
          break
        if op == DUP_TOP:
          has_multiple += 1
        j -= 1

      if has_unpack:
        return Statement.make_assign_unpack(i, bytecode, unpack_num=num_unpack)
      elif has_ROT_2_3:
        return Statement.make_assign_opt_unpack(i, bytecode)
      elif has_multiple > 0:
        return Statement.make_assign_chained(i, bytecode)
      else:
        # A simple assignment
        i, store_expr = Statement.make_expr(i, bytecode)
        i, value_expr = Statement.make_expr(i - 1, bytecode)
        return i, _ast.Assign([store_expr], value_expr)
    return i, None


  # 2 cases here:
  #  (1) a, b, c = foo() <=> v = foo(), a = v[0], b = v[1], c = v[2]
  #    => AST: _ast.Assign(targets=[Tuple(a, b, c)], value=foo())
  #
  #  (2) a, b = foo(), bar() <=> a = foo(), b = bar()
  #    => AST: _ast.Assign(targets=[Tuple(a, b)], value=Tuple(baz(), bar())) 
开发者ID:neuroo,项目名称:equip,代码行数:59,代码来源:stmt.py


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