Skip to content

Commit 143fd96

Browse files
Fix tests.
1 parent c01d7db commit 143fd96

1 file changed

Lines changed: 10 additions & 29 deletions

File tree

Lib/test/_test_atexit.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,35 +137,16 @@ def func():
137137

138138
def test_eq_unregister_clear(self):
139139
# Issue #112127: callback's __eq__ may call unregister or _clear
140-
cnt = 0
141-
class Func:
142-
def __init__(self, action, eq_ret_val):
143-
self.action = action
144-
self.eq_ret_val = eq_ret_val
145-
146-
def __call__(self):
147-
return
148-
149-
def __eq__(self, o):
150-
nonlocal cnt
151-
cnt += 1
152-
if cnt == 1:
153-
self.action(o)
154-
return self.eq_ret_val(o)
155-
156-
for action in (
157-
lambda o: atexit.unregister(self),
158-
lambda o: atexit.unregister(o),
159-
lambda o: atexit._clear()
160-
):
161-
for eq_ret_val in NotImplemented, True:
162-
with self.subTest(action=action, eq_ret_val=eq_ret_val):
163-
cnt = 0
164-
f1 = Func(action, eq_ret_val)
165-
f2 = Func(action, eq_ret_val)
166-
atexit.register(f1)
167-
atexit.register(f2)
168-
atexit._run_exitfuncs()
140+
class Evil:
141+
def __eq__(self, other):
142+
action(other)
143+
return NotImplemented
144+
145+
for action in atexit.unregister, lambda o: atexit._clear():
146+
with self.subTest(action=action):
147+
atexit.register(lambda: None)
148+
atexit.unregister(Evil())
149+
atexit._clear()
169150

170151

171152
if __name__ == "__main__":

0 commit comments

Comments
 (0)