File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 11import unittest
2+ import dis
23
34class TestCellWriteBarrier (unittest .TestCase ):
45 class A :
@@ -75,5 +76,30 @@ def test_cell_replace_same_bridge(self):
7576 # since this writes replaces the previous owning reference
7677 c .cell_contents = child
7778
79+ class TestBytecodeWriteBarrier (unittest .TestCase ):
80+ def test_delete_deref (self ):
81+ r = Region ()
82+ r .field = {}
83+ x = r .field
84+
85+ # Make sure the region knows about local reference from x
86+ self .assertFalse (r .try_close ())
87+
88+ def del_x ():
89+ nonlocal x
90+ del x # This triggers the DELETE_DEREF opcode
91+
92+ # Create the function and disassemble to confirm DELETE_DEREF is present
93+ bytecode = dis .Bytecode (del_x )
94+ self .assertIn ("DELETE_DEREF" , [instr .opname for instr in bytecode ])
95+
96+ self .assertTrue (r .is_open ())
97+
98+ # Call the function forcing the deletion of x which should
99+ # close the region.
100+ del_x ()
101+
102+ self .assertFalse (r .is_open ())
103+
78104if __name__ == "__main__" :
79105 unittest .main ()
You can’t perform that action at this time.
0 commit comments