mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
gh-134657: Remove newly added private names from asyncio.__all__ (#134665)
This commit is contained in:
parent
f1dcf3c7bf
commit
797abd1f7f
47 changed files with 105 additions and 90 deletions
|
@ -51,15 +51,24 @@ else:
|
||||||
def __getattr__(name: str):
|
def __getattr__(name: str):
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
deprecated = {
|
match name:
|
||||||
"AbstractEventLoopPolicy",
|
case "AbstractEventLoopPolicy":
|
||||||
"DefaultEventLoopPolicy",
|
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
|
||||||
"WindowsSelectorEventLoopPolicy",
|
return events._AbstractEventLoopPolicy
|
||||||
"WindowsProactorEventLoopPolicy",
|
case "DefaultEventLoopPolicy":
|
||||||
}
|
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
|
||||||
if name in deprecated:
|
if sys.platform == 'win32':
|
||||||
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
|
return windows_events._DefaultEventLoopPolicy
|
||||||
# deprecated things have underscores in front of them
|
return unix_events._DefaultEventLoopPolicy
|
||||||
return globals()["_" + name]
|
case "WindowsSelectorEventLoopPolicy":
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
|
||||||
|
return windows_events._WindowsSelectorEventLoopPolicy
|
||||||
|
# Else fall through to the AttributeError below.
|
||||||
|
case "WindowsProactorEventLoopPolicy":
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
|
||||||
|
return windows_events._WindowsProactorEventLoopPolicy
|
||||||
|
# Else fall through to the AttributeError below.
|
||||||
|
|
||||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||||
|
|
|
@ -5,14 +5,11 @@
|
||||||
# SPDX-FileCopyrightText: Copyright (c) 2015-2021 MagicStack Inc. http://magic.io
|
# SPDX-FileCopyrightText: Copyright (c) 2015-2021 MagicStack Inc. http://magic.io
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
"_AbstractEventLoopPolicy",
|
|
||||||
"AbstractEventLoop",
|
"AbstractEventLoop",
|
||||||
"AbstractServer",
|
"AbstractServer",
|
||||||
"Handle",
|
"Handle",
|
||||||
"TimerHandle",
|
"TimerHandle",
|
||||||
"_get_event_loop_policy",
|
|
||||||
"get_event_loop_policy",
|
"get_event_loop_policy",
|
||||||
"_set_event_loop_policy",
|
|
||||||
"set_event_loop_policy",
|
"set_event_loop_policy",
|
||||||
"get_event_loop",
|
"get_event_loop",
|
||||||
"set_event_loop",
|
"set_event_loop",
|
||||||
|
@ -791,7 +788,10 @@ def _init_event_loop_policy():
|
||||||
global _event_loop_policy
|
global _event_loop_policy
|
||||||
with _lock:
|
with _lock:
|
||||||
if _event_loop_policy is None: # pragma: no branch
|
if _event_loop_policy is None: # pragma: no branch
|
||||||
from . import _DefaultEventLoopPolicy
|
if sys.platform == 'win32':
|
||||||
|
from .windows_events import _DefaultEventLoopPolicy
|
||||||
|
else:
|
||||||
|
from .unix_events import _DefaultEventLoopPolicy
|
||||||
_event_loop_policy = _DefaultEventLoopPolicy()
|
_event_loop_policy = _DefaultEventLoopPolicy()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ from .log import logger
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'SelectorEventLoop',
|
'SelectorEventLoop',
|
||||||
'_DefaultEventLoopPolicy',
|
|
||||||
'EventLoop',
|
'EventLoop',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ class saved_test_environment:
|
||||||
return support.maybe_get_event_loop_policy()
|
return support.maybe_get_event_loop_policy()
|
||||||
def restore_asyncio_events__event_loop_policy(self, policy):
|
def restore_asyncio_events__event_loop_policy(self, policy):
|
||||||
asyncio = self.get_module('asyncio')
|
asyncio = self.get_module('asyncio')
|
||||||
asyncio._set_event_loop_policy(policy)
|
asyncio.events._set_event_loop_policy(policy)
|
||||||
|
|
||||||
def get_sys_argv(self):
|
def get_sys_argv(self):
|
||||||
return id(sys.argv), sys.argv, sys.argv[:]
|
return id(sys.argv), sys.argv, sys.argv[:]
|
||||||
|
|
|
@ -629,7 +629,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.loop.close()
|
self.loop.close()
|
||||||
self.loop = None
|
self.loop = None
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
def check_async_iterator_anext(self, ait_class):
|
def check_async_iterator_anext(self, ait_class):
|
||||||
with self.subTest(anext="pure-Python"):
|
with self.subTest(anext="pure-Python"):
|
||||||
|
|
|
@ -29,7 +29,7 @@ class CustomError(Exception):
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def mock_socket_module():
|
def mock_socket_module():
|
||||||
|
|
|
@ -5,7 +5,7 @@ from test.test_asyncio import functional as func_tests
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class ReceiveStuffProto(asyncio.BufferedProtocol):
|
class ReceiveStuffProto(asyncio.BufferedProtocol):
|
||||||
|
|
|
@ -4,7 +4,7 @@ import unittest
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(decimal.HAVE_CONTEXTVAR, "decimal is built with a thread-local context")
|
@unittest.skipUnless(decimal.HAVE_CONTEXTVAR, "decimal is built with a thread-local context")
|
||||||
|
|
|
@ -13,7 +13,7 @@ MOCK_ANY = mock.ANY
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class EagerTaskFactoryLoopTests:
|
class EagerTaskFactoryLoopTests:
|
||||||
|
|
|
@ -38,7 +38,7 @@ from test.support import threading_helper
|
||||||
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
|
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def broken_unix_getsockname():
|
def broken_unix_getsockname():
|
||||||
|
@ -2843,13 +2843,13 @@ class PolicyTests(unittest.TestCase):
|
||||||
self.assertIsInstance(policy, asyncio.DefaultEventLoopPolicy)
|
self.assertIsInstance(policy, asyncio.DefaultEventLoopPolicy)
|
||||||
|
|
||||||
def test_event_loop_policy(self):
|
def test_event_loop_policy(self):
|
||||||
policy = asyncio._AbstractEventLoopPolicy()
|
policy = asyncio.events._AbstractEventLoopPolicy()
|
||||||
self.assertRaises(NotImplementedError, policy.get_event_loop)
|
self.assertRaises(NotImplementedError, policy.get_event_loop)
|
||||||
self.assertRaises(NotImplementedError, policy.set_event_loop, object())
|
self.assertRaises(NotImplementedError, policy.set_event_loop, object())
|
||||||
self.assertRaises(NotImplementedError, policy.new_event_loop)
|
self.assertRaises(NotImplementedError, policy.new_event_loop)
|
||||||
|
|
||||||
def test_get_event_loop(self):
|
def test_get_event_loop(self):
|
||||||
policy = asyncio._DefaultEventLoopPolicy()
|
policy = test_utils.DefaultEventLoopPolicy()
|
||||||
self.assertIsNone(policy._local._loop)
|
self.assertIsNone(policy._local._loop)
|
||||||
|
|
||||||
with self.assertRaises(RuntimeError):
|
with self.assertRaises(RuntimeError):
|
||||||
|
@ -2857,7 +2857,7 @@ class PolicyTests(unittest.TestCase):
|
||||||
self.assertIsNone(policy._local._loop)
|
self.assertIsNone(policy._local._loop)
|
||||||
|
|
||||||
def test_get_event_loop_does_not_call_set_event_loop(self):
|
def test_get_event_loop_does_not_call_set_event_loop(self):
|
||||||
policy = asyncio._DefaultEventLoopPolicy()
|
policy = test_utils.DefaultEventLoopPolicy()
|
||||||
|
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
policy, "set_event_loop",
|
policy, "set_event_loop",
|
||||||
|
@ -2869,7 +2869,7 @@ class PolicyTests(unittest.TestCase):
|
||||||
m_set_event_loop.assert_not_called()
|
m_set_event_loop.assert_not_called()
|
||||||
|
|
||||||
def test_get_event_loop_after_set_none(self):
|
def test_get_event_loop_after_set_none(self):
|
||||||
policy = asyncio._DefaultEventLoopPolicy()
|
policy = test_utils.DefaultEventLoopPolicy()
|
||||||
policy.set_event_loop(None)
|
policy.set_event_loop(None)
|
||||||
self.assertRaises(RuntimeError, policy.get_event_loop)
|
self.assertRaises(RuntimeError, policy.get_event_loop)
|
||||||
|
|
||||||
|
@ -2877,7 +2877,7 @@ class PolicyTests(unittest.TestCase):
|
||||||
def test_get_event_loop_thread(self, m_current_thread):
|
def test_get_event_loop_thread(self, m_current_thread):
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
policy = asyncio._DefaultEventLoopPolicy()
|
policy = test_utils.DefaultEventLoopPolicy()
|
||||||
self.assertRaises(RuntimeError, policy.get_event_loop)
|
self.assertRaises(RuntimeError, policy.get_event_loop)
|
||||||
|
|
||||||
th = threading.Thread(target=f)
|
th = threading.Thread(target=f)
|
||||||
|
@ -2885,14 +2885,14 @@ class PolicyTests(unittest.TestCase):
|
||||||
th.join()
|
th.join()
|
||||||
|
|
||||||
def test_new_event_loop(self):
|
def test_new_event_loop(self):
|
||||||
policy = asyncio._DefaultEventLoopPolicy()
|
policy = test_utils.DefaultEventLoopPolicy()
|
||||||
|
|
||||||
loop = policy.new_event_loop()
|
loop = policy.new_event_loop()
|
||||||
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
|
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
def test_set_event_loop(self):
|
def test_set_event_loop(self):
|
||||||
policy = asyncio._DefaultEventLoopPolicy()
|
policy = test_utils.DefaultEventLoopPolicy()
|
||||||
old_loop = policy.new_event_loop()
|
old_loop = policy.new_event_loop()
|
||||||
policy.set_event_loop(old_loop)
|
policy.set_event_loop(old_loop)
|
||||||
|
|
||||||
|
@ -2909,7 +2909,7 @@ class PolicyTests(unittest.TestCase):
|
||||||
with self.assertWarnsRegex(
|
with self.assertWarnsRegex(
|
||||||
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
|
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
|
||||||
policy = asyncio.get_event_loop_policy()
|
policy = asyncio.get_event_loop_policy()
|
||||||
self.assertIsInstance(policy, asyncio._AbstractEventLoopPolicy)
|
self.assertIsInstance(policy, asyncio.events._AbstractEventLoopPolicy)
|
||||||
self.assertIs(policy, asyncio.get_event_loop_policy())
|
self.assertIs(policy, asyncio.get_event_loop_policy())
|
||||||
|
|
||||||
def test_set_event_loop_policy(self):
|
def test_set_event_loop_policy(self):
|
||||||
|
@ -2922,7 +2922,7 @@ class PolicyTests(unittest.TestCase):
|
||||||
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
|
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
|
||||||
old_policy = asyncio.get_event_loop_policy()
|
old_policy = asyncio.get_event_loop_policy()
|
||||||
|
|
||||||
policy = asyncio._DefaultEventLoopPolicy()
|
policy = test_utils.DefaultEventLoopPolicy()
|
||||||
with self.assertWarnsRegex(
|
with self.assertWarnsRegex(
|
||||||
DeprecationWarning, "'asyncio.set_event_loop_policy' is deprecated"):
|
DeprecationWarning, "'asyncio.set_event_loop_policy' is deprecated"):
|
||||||
asyncio.set_event_loop_policy(policy)
|
asyncio.set_event_loop_policy(policy)
|
||||||
|
@ -3034,13 +3034,13 @@ class GetEventLoopTestsMixin:
|
||||||
class TestError(Exception):
|
class TestError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Policy(asyncio._DefaultEventLoopPolicy):
|
class Policy(test_utils.DefaultEventLoopPolicy):
|
||||||
def get_event_loop(self):
|
def get_event_loop(self):
|
||||||
raise TestError
|
raise TestError
|
||||||
|
|
||||||
old_policy = asyncio._get_event_loop_policy()
|
old_policy = asyncio.events._get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
asyncio._set_event_loop_policy(Policy())
|
asyncio.events._set_event_loop_policy(Policy())
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
|
|
||||||
with self.assertRaises(TestError):
|
with self.assertRaises(TestError):
|
||||||
|
@ -3068,7 +3068,7 @@ class GetEventLoopTestsMixin:
|
||||||
asyncio.get_event_loop()
|
asyncio.get_event_loop()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
asyncio._set_event_loop_policy(old_policy)
|
asyncio.events._set_event_loop_policy(old_policy)
|
||||||
if loop is not None:
|
if loop is not None:
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
@ -3078,9 +3078,9 @@ class GetEventLoopTestsMixin:
|
||||||
self.assertIs(asyncio._get_running_loop(), None)
|
self.assertIs(asyncio._get_running_loop(), None)
|
||||||
|
|
||||||
def test_get_event_loop_returns_running_loop2(self):
|
def test_get_event_loop_returns_running_loop2(self):
|
||||||
old_policy = asyncio._get_event_loop_policy()
|
old_policy = asyncio.events._get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
asyncio._set_event_loop_policy(asyncio._DefaultEventLoopPolicy())
|
asyncio.events._set_event_loop_policy(test_utils.DefaultEventLoopPolicy())
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
self.addCleanup(loop.close)
|
self.addCleanup(loop.close)
|
||||||
|
|
||||||
|
@ -3106,7 +3106,7 @@ class GetEventLoopTestsMixin:
|
||||||
asyncio.get_event_loop()
|
asyncio.get_event_loop()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
asyncio._set_event_loop_policy(old_policy)
|
asyncio.events._set_event_loop_policy(old_policy)
|
||||||
if loop is not None:
|
if loop is not None:
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class MyException(Exception):
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestFreeThreading:
|
class TestFreeThreading:
|
||||||
|
|
|
@ -17,7 +17,7 @@ from test import support
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def _fakefunc(f):
|
def _fakefunc(f):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from asyncio import tasks
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class FutureTests:
|
class FutureTests:
|
||||||
|
|
|
@ -5,7 +5,7 @@ import unittest
|
||||||
|
|
||||||
# To prevent a warning "test altered the execution environment"
|
# To prevent a warning "test altered the execution environment"
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def capture_test_stack(*, fut=None, depth=1):
|
def capture_test_stack(*, fut=None, depth=1):
|
||||||
|
|
|
@ -20,7 +20,7 @@ RGX_REPR = re.compile(STR_RGX_REPR)
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class LockTests(unittest.IsolatedAsyncioTestCase):
|
class LockTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
|
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
|
||||||
|
|
|
@ -18,7 +18,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def close_transport(transport):
|
def close_transport(transport):
|
||||||
|
|
|
@ -7,7 +7,7 @@ import asyncio
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
# not needed for the test file but added for uniformness with all other
|
# not needed for the test file but added for uniformness with all other
|
||||||
# asyncio test files for the sake of unified cleanup
|
# asyncio test files for the sake of unified cleanup
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class ProtocolsAbsTests(unittest.TestCase):
|
class ProtocolsAbsTests(unittest.TestCase):
|
||||||
|
|
|
@ -6,7 +6,7 @@ from types import GenericAlias
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class QueueBasicTests(unittest.IsolatedAsyncioTestCase):
|
class QueueBasicTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -12,14 +12,14 @@ from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
def interrupt_self():
|
def interrupt_self():
|
||||||
_thread.interrupt_main()
|
_thread.interrupt_main()
|
||||||
|
|
||||||
|
|
||||||
class TestPolicy(asyncio._AbstractEventLoopPolicy):
|
class TestPolicy(asyncio.events._AbstractEventLoopPolicy):
|
||||||
|
|
||||||
def __init__(self, loop_factory):
|
def __init__(self, loop_factory):
|
||||||
self.loop_factory = loop_factory
|
self.loop_factory = loop_factory
|
||||||
|
@ -61,15 +61,15 @@ class BaseTest(unittest.TestCase):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
policy = TestPolicy(self.new_loop)
|
policy = TestPolicy(self.new_loop)
|
||||||
asyncio._set_event_loop_policy(policy)
|
asyncio.events._set_event_loop_policy(policy)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
policy = asyncio._get_event_loop_policy()
|
policy = asyncio.events._get_event_loop_policy()
|
||||||
if policy.loop is not None:
|
if policy.loop is not None:
|
||||||
self.assertTrue(policy.loop.is_closed())
|
self.assertTrue(policy.loop.is_closed())
|
||||||
self.assertTrue(policy.loop.shutdown_ag_run)
|
self.assertTrue(policy.loop.shutdown_ag_run)
|
||||||
|
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ class RunTests(BaseTest):
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
return 42
|
return 42
|
||||||
|
|
||||||
policy = asyncio._get_event_loop_policy()
|
policy = asyncio.events._get_event_loop_policy()
|
||||||
policy.set_event_loop = mock.Mock()
|
policy.set_event_loop = mock.Mock()
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
self.assertTrue(policy.set_event_loop.called)
|
self.assertTrue(policy.set_event_loop.called)
|
||||||
|
@ -259,7 +259,7 @@ class RunTests(BaseTest):
|
||||||
loop.set_task_factory(Task)
|
loop.set_task_factory(Task)
|
||||||
return loop
|
return loop
|
||||||
|
|
||||||
asyncio._set_event_loop_policy(TestPolicy(new_event_loop))
|
asyncio.events._set_event_loop_policy(TestPolicy(new_event_loop))
|
||||||
with self.assertRaises(asyncio.CancelledError):
|
with self.assertRaises(asyncio.CancelledError):
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
@ -495,7 +495,7 @@ class RunnerTests(BaseTest):
|
||||||
async def coro():
|
async def coro():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
policy = asyncio._get_event_loop_policy()
|
policy = asyncio.events._get_event_loop_policy()
|
||||||
policy.set_event_loop = mock.Mock()
|
policy.set_event_loop = mock.Mock()
|
||||||
runner = asyncio.Runner()
|
runner = asyncio.Runner()
|
||||||
runner.run(coro())
|
runner.run(coro())
|
||||||
|
|
|
@ -24,7 +24,7 @@ MOCK_ANY = mock.ANY
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
|
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
|
||||||
|
|
|
@ -22,7 +22,7 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MySendfileProto(asyncio.Protocol):
|
class MySendfileProto(asyncio.Protocol):
|
||||||
|
|
|
@ -11,7 +11,7 @@ from test.test_asyncio import functional as func_tests
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class BaseStartServer(func_tests.FunctionalTestCaseMixin):
|
class BaseStartServer(func_tests.FunctionalTestCaseMixin):
|
||||||
|
|
|
@ -15,7 +15,7 @@ if socket_helper.tcp_blackhole():
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MyProto(asyncio.Protocol):
|
class MyProto(asyncio.Protocol):
|
||||||
|
|
|
@ -30,7 +30,7 @@ BUF_MULTIPLIER = 1024 if not MACOS else 64
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MyBaseProto(asyncio.Protocol):
|
class MyBaseProto(asyncio.Protocol):
|
||||||
|
|
|
@ -21,7 +21,7 @@ from test.test_asyncio import functional as func_tests
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(ssl is None, 'No ssl module')
|
@unittest.skipIf(ssl is None, 'No ssl module')
|
||||||
|
|
|
@ -8,7 +8,7 @@ support.requires_working_socket(module=True)
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class StaggeredTests(unittest.IsolatedAsyncioTestCase):
|
class StaggeredTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -18,7 +18,7 @@ from test.support import socket_helper
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class StreamTests(test_utils.TestCase):
|
class StreamTests(test_utils.TestCase):
|
||||||
|
|
|
@ -37,7 +37,7 @@ PROGRAM_CAT = [
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):
|
class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):
|
||||||
|
|
|
@ -15,7 +15,7 @@ from test.test_asyncio.utils import await_without_task
|
||||||
|
|
||||||
# To prevent a warning "test altered the execution environment"
|
# To prevent a warning "test altered the execution environment"
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MyExc(Exception):
|
class MyExc(Exception):
|
||||||
|
|
|
@ -24,7 +24,7 @@ from test.support.warnings_helper import ignore_warnings
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
async def coroutine_function():
|
async def coroutine_function():
|
||||||
|
|
|
@ -8,7 +8,7 @@ from unittest import mock
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class ToThreadTests(unittest.IsolatedAsyncioTestCase):
|
class ToThreadTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from test.test_asyncio.utils import await_without_task
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
class TimeoutTests(unittest.IsolatedAsyncioTestCase):
|
class TimeoutTests(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from asyncio import transports
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
# not needed for the test file but added for uniformness with all other
|
# not needed for the test file but added for uniformness with all other
|
||||||
# asyncio test files for the sake of unified cleanup
|
# asyncio test files for the sake of unified cleanup
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TransportTests(unittest.TestCase):
|
class TransportTests(unittest.TestCase):
|
||||||
|
|
|
@ -30,7 +30,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
MOCK_ANY = mock.ANY
|
MOCK_ANY = mock.ANY
|
||||||
|
|
|
@ -5,7 +5,7 @@ from test import support
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
# The following value can be used as a very small timeout:
|
# The following value can be used as a very small timeout:
|
||||||
|
|
|
@ -19,7 +19,7 @@ from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class UpperProto(asyncio.Protocol):
|
class UpperProto(asyncio.Protocol):
|
||||||
|
@ -330,16 +330,16 @@ class WinPolicyTests(WindowsEventsTestCase):
|
||||||
async def main():
|
async def main():
|
||||||
self.assertIsInstance(asyncio.get_running_loop(), asyncio.SelectorEventLoop)
|
self.assertIsInstance(asyncio.get_running_loop(), asyncio.SelectorEventLoop)
|
||||||
|
|
||||||
old_policy = asyncio._get_event_loop_policy()
|
old_policy = asyncio.events._get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
with self.assertWarnsRegex(
|
with self.assertWarnsRegex(
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
"'asyncio.WindowsSelectorEventLoopPolicy' is deprecated",
|
"'asyncio.WindowsSelectorEventLoopPolicy' is deprecated",
|
||||||
):
|
):
|
||||||
asyncio._set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
asyncio.events._set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
finally:
|
finally:
|
||||||
asyncio._set_event_loop_policy(old_policy)
|
asyncio.events._set_event_loop_policy(old_policy)
|
||||||
|
|
||||||
def test_proactor_win_policy(self):
|
def test_proactor_win_policy(self):
|
||||||
async def main():
|
async def main():
|
||||||
|
@ -347,16 +347,16 @@ class WinPolicyTests(WindowsEventsTestCase):
|
||||||
asyncio.get_running_loop(),
|
asyncio.get_running_loop(),
|
||||||
asyncio.ProactorEventLoop)
|
asyncio.ProactorEventLoop)
|
||||||
|
|
||||||
old_policy = asyncio._get_event_loop_policy()
|
old_policy = asyncio.events._get_event_loop_policy()
|
||||||
try:
|
try:
|
||||||
with self.assertWarnsRegex(
|
with self.assertWarnsRegex(
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
"'asyncio.WindowsProactorEventLoopPolicy' is deprecated",
|
"'asyncio.WindowsProactorEventLoopPolicy' is deprecated",
|
||||||
):
|
):
|
||||||
asyncio._set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
asyncio.events._set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
finally:
|
finally:
|
||||||
asyncio._set_event_loop_policy(old_policy)
|
asyncio.events._set_event_loop_policy(old_policy)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -16,7 +16,7 @@ from test import support
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class PipeTests(unittest.TestCase):
|
class PipeTests(unittest.TestCase):
|
||||||
|
|
|
@ -601,3 +601,9 @@ async def await_without_task(coro):
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
if exc is not None:
|
if exc is not None:
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
|
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
DefaultEventLoopPolicy = asyncio.windows_events._DefaultEventLoopPolicy
|
||||||
|
else:
|
||||||
|
DefaultEventLoopPolicy = asyncio.unix_events._DefaultEventLoopPolicy
|
||||||
|
|
|
@ -512,7 +512,7 @@ class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):
|
||||||
# tests left a policy in place, just in case.
|
# tests left a policy in place, just in case.
|
||||||
policy = support.maybe_get_event_loop_policy()
|
policy = support.maybe_get_event_loop_policy()
|
||||||
assert policy is None, policy
|
assert policy is None, policy
|
||||||
cls.addClassCleanup(lambda: asyncio._set_event_loop_policy(None))
|
cls.addClassCleanup(lambda: asyncio.events._set_event_loop_policy(None))
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
|
@ -2307,7 +2307,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
loop.close()
|
loop.close()
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
self.assertEqual(buffer, [1, 2, 'MyException'])
|
self.assertEqual(buffer, [1, 2, 'MyException'])
|
||||||
|
|
||||||
|
|
|
@ -2820,7 +2820,7 @@ class TestGetAsyncGenState(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
def _asyncgenstate(self):
|
def _asyncgenstate(self):
|
||||||
return inspect.getasyncgenstate(self.asyncgen)
|
return inspect.getasyncgenstate(self.asyncgen)
|
||||||
|
|
|
@ -5421,7 +5421,7 @@ class LogRecordTest(BaseTest):
|
||||||
logging.logAsyncioTasks = False
|
logging.logAsyncioTasks = False
|
||||||
runner.run(make_record(self.assertIsNone))
|
runner.run(make_record(self.assertIsNone))
|
||||||
finally:
|
finally:
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
@support.requires_working_socket()
|
@support.requires_working_socket()
|
||||||
def test_taskName_without_asyncio_imported(self):
|
def test_taskName_without_asyncio_imported(self):
|
||||||
|
@ -5433,7 +5433,7 @@ class LogRecordTest(BaseTest):
|
||||||
logging.logAsyncioTasks = False
|
logging.logAsyncioTasks = False
|
||||||
runner.run(make_record(self.assertIsNone))
|
runner.run(make_record(self.assertIsNone))
|
||||||
finally:
|
finally:
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class BasicConfigTest(unittest.TestCase):
|
class BasicConfigTest(unittest.TestCase):
|
||||||
|
@ -5758,7 +5758,7 @@ class BasicConfigTest(unittest.TestCase):
|
||||||
data = f.read().strip()
|
data = f.read().strip()
|
||||||
self.assertRegex(data, r'Task-\d+ - hello world')
|
self.assertRegex(data, r'Task-\d+ - hello world')
|
||||||
finally:
|
finally:
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
if handler:
|
if handler:
|
||||||
handler.close()
|
handler.close()
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ requires_splice_pipe = unittest.skipIf(sys.platform.startswith("aix"),
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class MiscTests(unittest.TestCase):
|
class MiscTests(unittest.TestCase):
|
||||||
|
|
|
@ -12,7 +12,7 @@ class MyException(Exception):
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class TestCM:
|
class TestCM:
|
||||||
|
@ -480,7 +480,7 @@ class TestAsyncCase(unittest.TestCase):
|
||||||
|
|
||||||
class TestCase1(unittest.IsolatedAsyncioTestCase):
|
class TestCase1(unittest.IsolatedAsyncioTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
asyncio._get_event_loop_policy().get_event_loop()
|
asyncio.events._get_event_loop_policy().get_event_loop()
|
||||||
|
|
||||||
async def test_demo1(self):
|
async def test_demo1(self):
|
||||||
pass
|
pass
|
||||||
|
@ -490,7 +490,7 @@ class TestAsyncCase(unittest.TestCase):
|
||||||
self.assertTrue(result.wasSuccessful())
|
self.assertTrue(result.wasSuccessful())
|
||||||
|
|
||||||
def test_loop_factory(self):
|
def test_loop_factory(self):
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
class TestCase1(unittest.IsolatedAsyncioTestCase):
|
class TestCase1(unittest.IsolatedAsyncioTestCase):
|
||||||
loop_factory = asyncio.EventLoop
|
loop_factory = asyncio.EventLoop
|
||||||
|
|
|
@ -15,7 +15,7 @@ from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock, Mock,
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
asyncio._set_event_loop_policy(None)
|
asyncio.events._set_event_loop_policy(None)
|
||||||
|
|
||||||
|
|
||||||
class AsyncClass:
|
class AsyncClass:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
:mod:`asyncio`: Remove some private names from ``asyncio.__all__``.
|
Loading…
Add table
Add a link
Reference in a new issue