File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
171152if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments