mirror of
https://github.com/python/cpython.git
synced 2025-08-09 11:29:45 +00:00
[3.11] gh-93453: Only emit deprecation warning in asyncio.get_event_loop when a new event loop is created (#99949)
It no longer emits a deprecation warning if the current event loop was set. Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
235f5fd2ca
commit
3fae04b10e
13 changed files with 109 additions and 123 deletions
|
@ -145,10 +145,8 @@ class BaseFutureTests:
|
|||
self.assertTrue(f.cancelled())
|
||||
|
||||
def test_constructor_without_loop(self):
|
||||
with self.assertWarns(DeprecationWarning) as cm:
|
||||
with self.assertRaisesRegex(RuntimeError, 'There is no current event loop'):
|
||||
self._new_future()
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
with self.assertRaisesRegex(RuntimeError, 'no current event loop'):
|
||||
self._new_future()
|
||||
|
||||
def test_constructor_use_running_loop(self):
|
||||
async def test():
|
||||
|
@ -158,12 +156,10 @@ class BaseFutureTests:
|
|||
self.assertIs(f.get_loop(), self.loop)
|
||||
|
||||
def test_constructor_use_global_loop(self):
|
||||
# Deprecated in 3.10
|
||||
# Deprecated in 3.10, undeprecated in 3.11.1
|
||||
asyncio.set_event_loop(self.loop)
|
||||
self.addCleanup(asyncio.set_event_loop, None)
|
||||
with self.assertWarns(DeprecationWarning) as cm:
|
||||
f = self._new_future()
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
f = self._new_future()
|
||||
self.assertIs(f._loop, self.loop)
|
||||
self.assertIs(f.get_loop(), self.loop)
|
||||
|
||||
|
@ -499,10 +495,8 @@ class BaseFutureTests:
|
|||
return (arg, threading.get_ident())
|
||||
ex = concurrent.futures.ThreadPoolExecutor(1)
|
||||
f1 = ex.submit(run, 'oi')
|
||||
with self.assertWarns(DeprecationWarning) as cm:
|
||||
with self.assertRaises(RuntimeError):
|
||||
asyncio.wrap_future(f1)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
with self.assertRaisesRegex(RuntimeError, 'no current event loop'):
|
||||
asyncio.wrap_future(f1)
|
||||
ex.shutdown(wait=True)
|
||||
|
||||
def test_wrap_future_use_running_loop(self):
|
||||
|
@ -517,16 +511,14 @@ class BaseFutureTests:
|
|||
ex.shutdown(wait=True)
|
||||
|
||||
def test_wrap_future_use_global_loop(self):
|
||||
# Deprecated in 3.10
|
||||
# Deprecated in 3.10, undeprecated in 3.11.1
|
||||
asyncio.set_event_loop(self.loop)
|
||||
self.addCleanup(asyncio.set_event_loop, None)
|
||||
def run(arg):
|
||||
return (arg, threading.get_ident())
|
||||
ex = concurrent.futures.ThreadPoolExecutor(1)
|
||||
f1 = ex.submit(run, 'oi')
|
||||
with self.assertWarns(DeprecationWarning) as cm:
|
||||
f2 = asyncio.wrap_future(f1)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
f2 = asyncio.wrap_future(f1)
|
||||
self.assertIs(self.loop, f2._loop)
|
||||
ex.shutdown(wait=True)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue