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


Python ast.AugAssign方法代码示例

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


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

示例1: expr_stmt_rewrite

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def expr_stmt_rewrite(lhs, ann, aug, aug_exp, rhs: t.Optional[list]):
    if rhs:
        as_store(lhs)
        *init, end = rhs
        for each in init:
            as_store(each)
        return ast.Assign([lhs, *init], end)

    if ann:
        as_store(lhs)
        anno, value = ann
        return ast.AnnAssign(lhs, anno, value, 1)

    if aug_exp:
        as_store(lhs)
        return ast.AugAssign(lhs, aug(), aug_exp)

    # NO AS STORE HERE!
    return ast.Expr(lhs) 
开发者ID:Xython,项目名称:YAPyPy,代码行数:21,代码来源:helper.py

示例2: assign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def assign(self, block, stmt):
    #Evaluate the assignment(s)
    value = stmt.value
    value_variable = None
    for i in range(len(stmt.targets)):
      target = stmt.targets[i]
      if isinstance(target, ast.Tuple):
        #Save intermediate results
        results = []
        #Evaluate individual assignments
        for (t, v) in zip(target.elts, stmt.value.elts):
          results.append(self.assign_single(block, v, t, multi=True))
        #Execute final assignments after intermediate calculations
        for result in results:
          block.add(result)
      else:
        result = self.assign_single(block, value, target, src_variable=value_variable)
        if result is not None:
          block.add(result)
          value_variable = result[-1].expr

  #Parses an augmenting assignment (AST AugAssign) 
开发者ID:undefx,项目名称:vecpy,代码行数:24,代码来源:parser.py

示例3: onelinerize

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def onelinerize(original):
    # original :: string
    # :: string
    t = ast.parse(original)
    table = symtable.symtable(original, '<string>', 'exec')

    original = original.strip()

    # If there's only one line anyways, be lazy
    if len(original.splitlines()) == 1 and \
       len(t.body) == 1 and \
       type(t.body[0]) in (ast.Delete, ast.Assign, ast.AugAssign, ast.Print,
                           ast.Raise, ast.Assert, ast.Import, ast.ImportFrom,
                           ast.Exec, ast.Global, ast.Expr, ast.Pass):
        return original

    return get_init_code(t, table) 
开发者ID:csvoss,项目名称:onelinerizer,代码行数:19,代码来源:onelinerizer.py

示例4: visit_AugAssign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def visit_AugAssign(self, node: ast.AugAssign) -> None:
        # +=, -=, /=, *=
        print(f"AugAssign: {node}")
        print(ast.dump(node))
        self.generic_visit(node) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:_devtools.py

示例5: __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:AtomLinter,项目名称:linter-pylama,代码行数:12,代码来源:checker.py

示例6: test_augassign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def test_augassign(self):
        aug = ast.AugAssign(ast.Name("x", ast.Load()), ast.Add(),
                            ast.Name("y", ast.Load()))
        self.stmt(aug, "must have Store context")
        aug = ast.AugAssign(ast.Name("x", ast.Store()), ast.Add(),
                            ast.Name("y", ast.Store()))
        self.stmt(aug, "must have Load context") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_ast.py

示例7: __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 = []

        def _add_to_names(container):
            for node in container.elts:
                if isinstance(node, ast.Str):
                    self.names.append(node.s)

        if isinstance(source.value, (ast.List, ast.Tuple)):
            _add_to_names(source.value)
        # If concatenating lists
        elif isinstance(source.value, ast.BinOp):
            currentValue = source.value
            while isinstance(currentValue.right, ast.List):
                left = currentValue.left
                right = currentValue.right
                _add_to_names(right)
                # If more lists are being added
                if isinstance(left, ast.BinOp):
                    currentValue = left
                # If just two lists are being added
                elif isinstance(left, ast.List):
                    _add_to_names(left)
                    # All lists accounted for - done
                    break
                # If not list concatenation
                else:
                    break
        super(ExportBinding, self).__init__(name, source) 
开发者ID:PyCQA,项目名称:pyflakes,代码行数:34,代码来源:checker.py

示例8: statement

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def statement(self, block, stmt):
    #Add a comment
    self.add_comment(block, stmt)
    #Parse the statement
    try:
      if isinstance(stmt, ast.Assign):
        self.assign(block, stmt)
      elif isinstance(stmt, ast.Return):
        self.return_(block, stmt)
      elif isinstance(stmt, ast.Expr):
        self.docstring_(block, stmt)
      elif isinstance(stmt, ast.If):
        self.if_(block, stmt)
      elif isinstance(stmt, ast.While):
        self.while_(block, stmt)
      elif isinstance(stmt, ast.AugAssign):
        self.augassign(block, stmt)
      else:
        Parser._dump(stmt, 'Unexpected Statement')
        raise Exception('Unexpected Statement (%s)'%(stmt.__class__))
    except:
      line = stmt.lineno
      src = self.source.split('\n')[line - 1].strip()
      print('Line %d: %s'%(line, src))
      raise

  #===========================================================
  # Public interface
  #===========================================================
  #Parses the kernel using the specified live function 
开发者ID:undefx,项目名称:vecpy,代码行数:32,代码来源:parser.py

示例9: p_expr_stmt_1

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def p_expr_stmt_1(p):
    '''expr_stmt : testlist augassign yield_expr'''
    #                     1         2          3
    ctx_to_store(p[1])
    p[0] = ast.AugAssign(p[1], p[2], p[3], rule=inspect.currentframe().f_code.co_name)
    inherit_lineno(p[0], p[1]) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:8,代码来源:hgawk_grammar.py

示例10: p_expr_stmt_2

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def p_expr_stmt_2(p):
    '''expr_stmt : testlist augassign testlist'''
    #                     1         2        3
    ctx_to_store(p[1])
    p[0] = ast.AugAssign(p[1], p[2], p[3], rule=inspect.currentframe().f_code.co_name)
    inherit_lineno(p[0], p[1]) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:8,代码来源:hgawk_grammar.py

示例11: gen_statement

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def gen_statement(self, statement):
        """ Generate code for a statement """
        if isinstance(statement, list):
            for inner_statement in statement:
                self.gen_statement(inner_statement)
        else:
            with self.use_location(statement):
                if isinstance(statement, ast.Pass):
                    pass  # No comments :)
                elif isinstance(statement, ast.Return):
                    self.gen_return(statement)
                elif isinstance(statement, ast.If):
                    self.gen_if(statement)
                elif isinstance(statement, ast.While):
                    self.gen_while(statement)
                elif isinstance(statement, ast.Break):
                    self.gen_break(statement)
                elif isinstance(statement, ast.Continue):
                    self.gen_continue(statement)
                elif isinstance(statement, ast.For):
                    self.gen_for(statement)
                elif isinstance(statement, ast.Assign):
                    self.gen_assign(statement)
                elif isinstance(statement, ast.Expr):
                    self.gen_expr(statement.value)
                elif isinstance(statement, ast.AugAssign):
                    self.gen_aug_assign(statement)
                else:  # pragma: no cover
                    self.not_impl(statement) 
开发者ID:windelbouwman,项目名称:ppci,代码行数:31,代码来源:python2ir.py

示例12: aug_assign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def aug_assign(d: ast.AugAssign):
    operator = find(d.op)
    value = find(d.value)
    target = find(d.target)
    return f"{target} = {target} {operator} {value};" 
开发者ID:timoniq,项目名称:vkbottle,代码行数:7,代码来源:definitions.py

示例13: visit_AugAssign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def visit_AugAssign(self, aug_assign: ast.AugAssign, _ctx: CPSTransformerContext) -> VisitReturnT:
        return aug_assign, [] 
开发者ID:NetSys,项目名称:kappa,代码行数:4,代码来源:cps.py

示例14: visit_AugAssign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def visit_AugAssign(self, aug_assign: ast.AugAssign) -> ActionsT:
        value, value_actions = self.visit_expr(aug_assign.value)
        target, target_actions = self.visit_expr(aug_assign.target)
        result_node = ast.AugAssign(target=target, op=aug_assign.op, value=value)
        return value_actions + target_actions + [result_node] 
开发者ID:NetSys,项目名称:kappa,代码行数:7,代码来源:flatten.py

示例15: visit_AugAssign

# 需要导入模块: import ast [as 别名]
# 或者: from ast import AugAssign [as 别名]
def visit_AugAssign(self, aug_assign: ast.AugAssign) -> None:
        self.visit_simple_stmt(aug_assign)
        # The variable assigned to is also live (`x` in `x += 5`).
        self._live_vars |= find_variables_by_usage(aug_assign.target)[ast.Store] 
开发者ID:NetSys,项目名称:kappa,代码行数:6,代码来源:liveness.py


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