Skip to content

gh-99051: remove duplicated test from test_weakref #99052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions Lib/test/test_weakref.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class C(object):
# deallocation of c2.
del c2

def test_callback_in_cycle_1(self):
def test_callback_in_cycle(self):
import gc

class J(object):
Expand Down Expand Up @@ -637,40 +637,11 @@ def acallback(self, ignore):
del I, J, II
gc.collect()

def test_callback_in_cycle_2(self):
def test_callback_reachable_one_way(self):
import gc

# This is just like test_callback_in_cycle_1, except that II is an
# old-style class. The symptom is different then: an instance of an
# 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
# This one broke the first patch that fixed the previous test. In this case,
# the objects reachable from the callback aren't also reachable
# 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__
# got tp_clear'ed by the time the c2.cb callback got invoked.
Expand All @@ -690,10 +661,10 @@ def cb(self, ignore):
del c1, c2
gc.collect()

def test_callback_in_cycle_4(self):
def test_callback_different_classes(self):
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
# 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.
Expand Down