Skip to content

Commit 6fadca3

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 5707792 commit 6fadca3

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
@@ -597,7 +597,7 @@ class C(object):
597597
# deallocation of c2.
598598
del c2
599599

600-
def test_callback_in_cycle_1(self):
600+
def test_callback_in_cycle(self):
601601
import gc
602602

603603
class J(object):
@@ -637,40 +637,11 @@ def acallback(self, ignore):
637637
del I, J, II
638638
gc.collect()
639639

640-
def test_callback_in_cycle_2(self):
640+
def test_callback_reachable_one_way(self):
641641
import gc
642642

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

693-
def test_callback_in_cycle_4(self):
664+
def test_callback_different_classes(self):
694665
import gc
695666

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

0 commit comments

Comments
 (0)