def op_SETUP_WITH(self, inst, contextmanager): assert self.blocks[inst.offset] is self.current_block exitpt = inst.next + inst.arg wth = ir.With(inst.offset, exit=exitpt) self.syntax_blocks.append(wth) self.current_block.append(ir.EnterWith( contextmanager=self.get(contextmanager), begin=inst.offset, end=exitpt, loc=self.loc, ))
def test_enterwith(self): a = ir.EnterWith(self.var_a, 0, 1, self.loc1) b = ir.EnterWith(self.var_a, 0, 1, self.loc1) c = ir.EnterWith(self.var_a, 0, 1, self.loc2) d = ir.EnterWith(self.var_b, 0, 1, self.loc1) e = ir.EnterWith(self.var_a, 1, 1, self.loc1) f = ir.EnterWith(self.var_a, 0, 2, self.loc1) self.check(a, same=[b, c], different=[d, e, f])