mirror of
https://github.com/python/cpython.git
synced 2025-09-20 07:31:10 +00:00
gh-99051: remove duplicated test from test_weakref
(GH-99052)
This commit is contained in:
parent
7dcd28eb41
commit
8463cb55da
1 changed files with 6 additions and 35 deletions
|
@ -597,7 +597,7 @@ class ReferencesTestCase(TestBase):
|
||||||
# deallocation of c2.
|
# deallocation of c2.
|
||||||
del c2
|
del c2
|
||||||
|
|
||||||
def test_callback_in_cycle_1(self):
|
def test_callback_in_cycle(self):
|
||||||
import gc
|
import gc
|
||||||
|
|
||||||
class J(object):
|
class J(object):
|
||||||
|
@ -637,40 +637,11 @@ class ReferencesTestCase(TestBase):
|
||||||
del I, J, II
|
del I, J, II
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def test_callback_in_cycle_2(self):
|
def test_callback_reachable_one_way(self):
|
||||||
import gc
|
import gc
|
||||||
|
|
||||||
# This is just like test_callback_in_cycle_1, except that II is an
|
# This one broke the first patch that fixed the previous test. In this case,
|
||||||
# old-style class. The symptom is different then: an instance of an
|
# the objects reachable from the callback aren't also reachable
|
||||||
# old-style class looks in its own __dict__ first. 'J' happens to
|
|
||||||
# get cleared from I.__dict__ before 'wr', and 'J' was never in II's
|
|
||||||
# __dict__, so the attribute isn't found. The difference is that
|
|
||||||
# the old-style II doesn't have a NULL __mro__ (it doesn't have any
|
|
||||||
# __mro__), so no segfault occurs. Instead it got:
|
|
||||||
# test_callback_in_cycle_2 (__main__.ReferencesTestCase) ...
|
|
||||||
# Exception exceptions.AttributeError:
|
|
||||||
# "II instance has no attribute 'J'" in <bound method II.acallback
|
|
||||||
# of <?.II instance at 0x00B9B4B8>> ignored
|
|
||||||
|
|
||||||
class J(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class II:
|
|
||||||
def acallback(self, ignore):
|
|
||||||
self.J
|
|
||||||
|
|
||||||
I = II()
|
|
||||||
I.J = J
|
|
||||||
I.wr = weakref.ref(J, I.acallback)
|
|
||||||
|
|
||||||
del I, J, II
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
def test_callback_in_cycle_3(self):
|
|
||||||
import gc
|
|
||||||
|
|
||||||
# This one broke the first patch that fixed the last two. In this
|
|
||||||
# case, the objects reachable from the callback aren't also reachable
|
|
||||||
# from the object (c1) *triggering* the callback: you can get to
|
# from the object (c1) *triggering* the callback: you can get to
|
||||||
# c1 from c2, but not vice-versa. The result was that c2's __dict__
|
# c1 from c2, but not vice-versa. The result was that c2's __dict__
|
||||||
# got tp_clear'ed by the time the c2.cb callback got invoked.
|
# got tp_clear'ed by the time the c2.cb callback got invoked.
|
||||||
|
@ -690,10 +661,10 @@ class ReferencesTestCase(TestBase):
|
||||||
del c1, c2
|
del c1, c2
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
def test_callback_in_cycle_4(self):
|
def test_callback_different_classes(self):
|
||||||
import gc
|
import gc
|
||||||
|
|
||||||
# Like test_callback_in_cycle_3, except c2 and c1 have different
|
# Like test_callback_reachable_one_way, except c2 and c1 have different
|
||||||
# classes. c2's class (C) isn't reachable from c1 then, so protecting
|
# classes. c2's class (C) isn't reachable from c1 then, so protecting
|
||||||
# objects reachable from the dying object (c1) isn't enough to stop
|
# objects reachable from the dying object (c1) isn't enough to stop
|
||||||
# c2's class (C) from getting tp_clear'ed before c2.cb is invoked.
|
# c2's class (C) from getting tp_clear'ed before c2.cb is invoked.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue