def visit_AugAssign(self, assign): self.update_position(assign.lineno, True) target = assign.target if isinstance(target, ast.Attribute): attr = ast.Attribute(target.value, target.attr, ast.AugLoad, target.lineno, target.col_offset) attr.walkabout(self) assign.value.walkabout(self) self.emit_op(self._op_for_augassign(assign.op)) attr.ctx = ast.AugStore attr.walkabout(self) elif isinstance(target, ast.Subscript): sub = ast.Subscript(target.value, target.slice, ast.AugLoad, target.lineno, target.col_offset) sub.walkabout(self) assign.value.walkabout(self) self.emit_op(self._op_for_augassign(assign.op)) sub.ctx = ast.AugStore sub.walkabout(self) elif isinstance(target, ast.Name): self.name_op(target.id, ast.Load) assign.value.walkabout(self) self.emit_op(self._op_for_augassign(assign.op)) self.name_op(target.id, ast.Store) else: self.error("illegal expression for augmented assignment", assign)
def test_attribute(self): attr = ast.Attribute(ast.Name("x", ast.Store, 0, 0), "y", ast.Load, 0, 0) self.expr(attr, "must have Load context")