本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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")
示例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)
示例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
示例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])
示例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])
示例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)
示例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};"
示例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, []
示例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]
示例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]