@@ -750,6 +750,10 @@ def test_future_cancelled_exception_refcycles(self):
750750 self .assertIsNotNone (exc )
751751 self .assertListEqual (gc .get_referrers (exc ), [])
752752
753+ def test_future_disallow_multiple_initialization (self ):
754+ f = self ._new_future (loop = self .loop )
755+ with self .assertRaises (RuntimeError , msg = "is already initialized" ):
756+ f .__init__ (loop = self .loop )
753757
754758@unittest .skipUnless (hasattr (futures , '_CFuture' ),
755759 'requires the C _asyncio module' )
@@ -1091,33 +1095,6 @@ def __getattribute__(self, name):
10911095 fut .add_done_callback (fut_callback_0 )
10921096 self .assertRaises (ReachableCode , fut .set_result , "boom" )
10931097
1094- def test_use_after_free_on_fut_context_0_with_evil__getattribute__ (self ):
1095- # see: https://github.com/python/cpython/issues/125984
1096-
1097- class EvilEventLoop (SimpleEvilEventLoop ):
1098- def call_soon (self , * args , ** kwargs ):
1099- super ().call_soon (* args , ** kwargs )
1100- raise ReachableCode
1101-
1102- def __getattribute__ (self , name ):
1103- if name == 'call_soon' :
1104- # resets the future's event loop
1105- fut .__init__ (loop = SimpleEvilEventLoop ())
1106- return object .__getattribute__ (self , name )
1107-
1108- evil_loop = EvilEventLoop ()
1109- with mock .patch .object (self , 'loop' , evil_loop ):
1110- fut = self ._new_future ()
1111- self .assertIs (fut .get_loop (), evil_loop )
1112-
1113- fut_callback_0 = mock .Mock ()
1114- fut_context_0 = mock .Mock ()
1115- fut .add_done_callback (fut_callback_0 , context = fut_context_0 )
1116- del fut_context_0
1117- del fut_callback_0
1118- self .assertRaises (ReachableCode , fut .set_result , "boom" )
1119-
1120-
11211098@unittest .skipUnless (hasattr (futures , '_CFuture' ),
11221099 'requires the C _asyncio module' )
11231100class CFutureDoneCallbackTests (BaseFutureDoneCallbackTests ,
0 commit comments