Skip to content

Commit cd6fe96

Browse files
gh-99051: remove duplicated test from test_weakref (GH-99052)
(cherry picked from commit 8463cb5) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent 380b12e commit cd6fe96

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

Lib/test/test_weakref.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ class C(object):
595595
# deallocation of c2.
596596
del c2
597597

598-
def test_callback_in_cycle_1(self):
598+
def test_callback_in_cycle(self):
599599
import gc
600600

601601
class J(object):
@@ -635,40 +635,11 @@ def acallback(self, ignore):
635635
del I, J, II
636636
gc.collect()
637637

638-
def test_callback_in_cycle_2(self):
638+
def test_callback_reachable_one_way(self):
639639
import gc
640640

641-
# This is just like test_callback_in_cycle_1, except that II is an
642-
# old-style class. The symptom is different then: an instance of an
643-
# old-style class looks in its own __dict__ first. 'J' happens to
644-
# get cleared from I.__dict__ before 'wr', and 'J' was never in II's
645-
# __dict__, so the attribute isn't found. The difference is that
646-
# the old-style II doesn't have a NULL __mro__ (it doesn't have any
647-
# __mro__), so no segfault occurs. Instead it got:
648-
# test_callback_in_cycle_2 (__main__.ReferencesTestCase) ...
649-
# Exception exceptions.AttributeError:
650-
# "II instance has no attribute 'J'" in <bound method II.acallback
651-
# of <?.II instance at 0x00B9B4B8>> ignored
652-
653-
class J(object):
654-
pass
655-
656-
class II:
657-
def acallback(self, ignore):
658-
self.J
659-
660-
I = II()
661-
I.J = J
662-
I.wr = weakref.ref(J, I.acallback)
663-
664-
del I, J, II
665-
gc.collect()
666-
667-
def test_callback_in_cycle_3(self):
668-
import gc
669-
670-
# This one broke the first patch that fixed the last two. In this
671-
# case, the objects reachable from the callback aren't also reachable
641+
# This one broke the first patch that fixed the previous test. In this case,
642+
# the objects reachable from the callback aren't also reachable
672643
# from the object (c1) *triggering* the callback: you can get to
673644
# c1 from c2, but not vice-versa. The result was that c2's __dict__
674645
# got tp_clear'ed by the time the c2.cb callback got invoked.
@@ -688,10 +659,10 @@ def cb(self, ignore):
688659
del c1, c2
689660
gc.collect()
690661

691-
def test_callback_in_cycle_4(self):
662+
def test_callback_different_classes(self):
692663
import gc
693664

694-
# Like test_callback_in_cycle_3, except c2 and c1 have different
665+
# Like test_callback_reachable_one_way, except c2 and c1 have different
695666
# classes. c2's class (C) isn't reachable from c1 then, so protecting
696667
# objects reachable from the dying object (c1) isn't enough to stop
697668
# c2's class (C) from getting tp_clear'ed before c2.cb is invoked.

0 commit comments

Comments
 (0)