Example #1
0
 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)
Example #2
0
def reduce_slice(obj, sliceobj):
    """generic factory for Slice nodes"""
    assert isinstance(sliceobj, SlicelistObject)
    if sliceobj.fake_rulename == 'slice':
        start = sliceobj.value[0]
        end = sliceobj.value[1]
        return ast.Slice(obj, consts.OP_APPLY, start, end, sliceobj.lineno)
    else:
        return ast.Subscript(obj, consts.OP_APPLY,
                             ast.Sliceobj(sliceobj.value, sliceobj.lineno),
                             sliceobj.lineno)
Example #3
0
 def test_subscript(self):
     sub = ast.Subscript(ast.Name("x", ast.Store, 0, 0),
                         ast.Index(ast.Num(self.space.wrap(3), 0, 0)),
                         ast.Load, 0, 0)
     self.expr(sub, "must have Load context")
     x = ast.Name("x", ast.Load, 0, 0)
     sub = ast.Subscript(x, ast.Index(ast.Name("y", ast.Store, 0, 0)),
                         ast.Load, 0, 0)
     self.expr(sub, "must have Load context")
     s = ast.Name("x", ast.Store, 0, 0)
     for args in (s, None, None), (None, s, None), (None, None, s):
         sl = ast.Slice(*args)
         self.expr(ast.Subscript(x, sl, ast.Load, 0, 0),
                   "must have Load context")
     sl = ast.ExtSlice([])
     self.expr(ast.Subscript(x, sl, ast.Load, 0, 0),
               "empty dims on ExtSlice")
     sl = ast.ExtSlice([ast.Index(s)])
     self.expr(ast.Subscript(x, sl, ast.Load, 0, 0),
               "must have Load context")
Example #4
0
def reduce_subscript(obj, subscript):
    """generic factory for Subscript nodes"""
    assert isinstance(subscript, SubscriptObject)
    return ast.Subscript(obj, consts.OP_APPLY, subscript.value,
                         subscript.lineno)