summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-07-09 08:34:19 (GMT)
committerGitHub <noreply@github.com>2025-07-09 08:34:19 (GMT)
commitc29fce05f3b4558f2dcd91ccaac5ab646caf6c1c (patch)
tree6f4a5e64975f38f477b0cae85c6ca82a292d1fc1
parenta9d2f08b579a400e0f2a337116bb29f476249dff (diff)
downloadcpython-c29fce05f3b4558f2dcd91ccaac5ab646caf6c1c.zip
cpython-c29fce05f3b4558f2dcd91ccaac5ab646caf6c1c.tar.gz
cpython-c29fce05f3b4558f2dcd91ccaac5ab646caf6c1c.tar.bz2
[3.14] gh-134657: Remove newly added private names from asyncio.__all__ (GH-134665) (#136455)
gh-134657: Remove newly added private names from asyncio.__all__ (GH-134665) (cherry picked from commit 797abd1f7fdeb744bf9f683ef844e7279aad3d72) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
-rw-r--r--Lib/asyncio/__init__.py29
-rw-r--r--Lib/asyncio/events.py8
-rw-r--r--Lib/asyncio/unix_events.py1
-rw-r--r--Lib/test/libregrtest/save_env.py2
-rw-r--r--Lib/test/test_asyncgen.py2
-rw-r--r--Lib/test/test_asyncio/test_base_events.py2
-rw-r--r--Lib/test/test_asyncio/test_buffered_proto.py2
-rw-r--r--Lib/test/test_asyncio/test_context.py2
-rw-r--r--Lib/test/test_asyncio/test_eager_task_factory.py2
-rw-r--r--Lib/test/test_asyncio/test_events.py34
-rw-r--r--Lib/test/test_asyncio/test_free_threading.py2
-rw-r--r--Lib/test/test_asyncio/test_futures.py2
-rw-r--r--Lib/test/test_asyncio/test_futures2.py2
-rw-r--r--Lib/test/test_asyncio/test_graph.py2
-rw-r--r--Lib/test/test_asyncio/test_locks.py2
-rw-r--r--Lib/test/test_asyncio/test_pep492.py2
-rw-r--r--Lib/test/test_asyncio/test_proactor_events.py2
-rw-r--r--Lib/test/test_asyncio/test_protocols.py2
-rw-r--r--Lib/test/test_asyncio/test_queues.py2
-rw-r--r--Lib/test/test_asyncio/test_runners.py16
-rw-r--r--Lib/test/test_asyncio/test_selector_events.py2
-rw-r--r--Lib/test/test_asyncio/test_sendfile.py2
-rw-r--r--Lib/test/test_asyncio/test_server.py2
-rw-r--r--Lib/test/test_asyncio/test_sock_lowlevel.py2
-rw-r--r--Lib/test/test_asyncio/test_ssl.py2
-rw-r--r--Lib/test/test_asyncio/test_sslproto.py2
-rw-r--r--Lib/test/test_asyncio/test_staggered.py2
-rw-r--r--Lib/test/test_asyncio/test_streams.py2
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py2
-rw-r--r--Lib/test/test_asyncio/test_taskgroups.py2
-rw-r--r--Lib/test/test_asyncio/test_tasks.py2
-rw-r--r--Lib/test/test_asyncio/test_threads.py2
-rw-r--r--Lib/test/test_asyncio/test_timeouts.py2
-rw-r--r--Lib/test/test_asyncio/test_transports.py2
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py2
-rw-r--r--Lib/test/test_asyncio/test_waitfor.py2
-rw-r--r--Lib/test/test_asyncio/test_windows_events.py14
-rw-r--r--Lib/test/test_asyncio/test_windows_utils.py2
-rw-r--r--Lib/test/test_asyncio/utils.py6
-rw-r--r--Lib/test/test_concurrent_futures/test_interpreter_pool.py2
-rw-r--r--Lib/test/test_coroutines.py2
-rw-r--r--Lib/test/test_inspect/test_inspect.py2
-rw-r--r--Lib/test/test_logging.py6
-rw-r--r--Lib/test/test_os.py2
-rw-r--r--Lib/test/test_unittest/test_async_case.py6
-rw-r--r--Lib/test/test_unittest/testmock/testasync.py2
-rw-r--r--Misc/NEWS.d/next/Library/2025-05-25-11-02-05.gh-issue-134657.3YFhR9.rst1
47 files changed, 105 insertions, 90 deletions
diff --git a/Lib/asyncio/__init__.py b/Lib/asyncio/__init__.py
index 4be7112..32a5dba 100644
--- a/Lib/asyncio/__init__.py
+++ b/Lib/asyncio/__init__.py
@@ -51,15 +51,24 @@ else:
def __getattr__(name: str):
import warnings
- deprecated = {
- "AbstractEventLoopPolicy",
- "DefaultEventLoopPolicy",
- "WindowsSelectorEventLoopPolicy",
- "WindowsProactorEventLoopPolicy",
- }
- if name in deprecated:
- warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
- # deprecated things have underscores in front of them
- return globals()["_" + name]
+ match name:
+ case "AbstractEventLoopPolicy":
+ warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
+ return events._AbstractEventLoopPolicy
+ case "DefaultEventLoopPolicy":
+ warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
+ if sys.platform == 'win32':
+ return windows_events._DefaultEventLoopPolicy
+ return unix_events._DefaultEventLoopPolicy
+ 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}")
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 2913f90..a7fb559 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -5,14 +5,11 @@
# SPDX-FileCopyrightText: Copyright (c) 2015-2021 MagicStack Inc. http://magic.io
__all__ = (
- "_AbstractEventLoopPolicy",
"AbstractEventLoop",
"AbstractServer",
"Handle",
"TimerHandle",
- "_get_event_loop_policy",
"get_event_loop_policy",
- "_set_event_loop_policy",
"set_event_loop_policy",
"get_event_loop",
"set_event_loop",
@@ -791,7 +788,10 @@ def _init_event_loop_policy():
global _event_loop_policy
with _lock:
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()
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index f69c6a6..1c14581 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -28,7 +28,6 @@ from .log import logger
__all__ = (
'SelectorEventLoop',
- '_DefaultEventLoopPolicy',
'EventLoop',
)
diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py
index ffc29fa..4cf1a07 100644
--- a/Lib/test/libregrtest/save_env.py
+++ b/Lib/test/libregrtest/save_env.py
@@ -97,7 +97,7 @@ class saved_test_environment:
return support.maybe_get_event_loop_policy()
def restore_asyncio_events__event_loop_policy(self, policy):
asyncio = self.get_module('asyncio')
- asyncio._set_event_loop_policy(policy)
+ asyncio.events._set_event_loop_policy(policy)
def get_sys_argv(self):
return id(sys.argv), sys.argv, sys.argv[:]
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
index 2f2865b..fc3bd7d 100644
--- a/Lib/test/test_asyncgen.py
+++ b/Lib/test/test_asyncgen.py
@@ -629,7 +629,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
def tearDown(self):
self.loop.close()
self.loop = None
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def check_async_iterator_anext(self, ait_class):
with self.subTest(anext="pure-Python"):
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 12179eb..1b727f3 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -29,7 +29,7 @@ class CustomError(Exception):
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def mock_socket_module():
diff --git a/Lib/test/test_asyncio/test_buffered_proto.py b/Lib/test/test_asyncio/test_buffered_proto.py
index 9c386dd..6d3edcc 100644
--- a/Lib/test/test_asyncio/test_buffered_proto.py
+++ b/Lib/test/test_asyncio/test_buffered_proto.py
@@ -5,7 +5,7 @@ from test.test_asyncio import functional as func_tests
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class ReceiveStuffProto(asyncio.BufferedProtocol):
diff --git a/Lib/test/test_asyncio/test_context.py b/Lib/test/test_asyncio/test_context.py
index ad394f4..f85f398 100644
--- a/Lib/test/test_asyncio/test_context.py
+++ b/Lib/test/test_asyncio/test_context.py
@@ -4,7 +4,7 @@ import unittest
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")
diff --git a/Lib/test/test_asyncio/test_eager_task_factory.py b/Lib/test/test_asyncio/test_eager_task_factory.py
index 9f3b6f9..da79ee9 100644
--- a/Lib/test/test_asyncio/test_eager_task_factory.py
+++ b/Lib/test/test_asyncio/test_eager_task_factory.py
@@ -13,7 +13,7 @@ MOCK_ANY = mock.ANY
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class EagerTaskFactoryLoopTests:
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 873c503..919d543 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -38,7 +38,7 @@ from test.support import threading_helper
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def broken_unix_getsockname():
@@ -2843,13 +2843,13 @@ class PolicyTests(unittest.TestCase):
self.assertIsInstance(policy, asyncio.DefaultEventLoopPolicy)
def test_event_loop_policy(self):
- policy = asyncio._AbstractEventLoopPolicy()
+ policy = asyncio.events._AbstractEventLoopPolicy()
self.assertRaises(NotImplementedError, policy.get_event_loop)
self.assertRaises(NotImplementedError, policy.set_event_loop, object())
self.assertRaises(NotImplementedError, policy.new_event_loop)
def test_get_event_loop(self):
- policy = asyncio._DefaultEventLoopPolicy()
+ policy = test_utils.DefaultEventLoopPolicy()
self.assertIsNone(policy._local._loop)
with self.assertRaises(RuntimeError):
@@ -2857,7 +2857,7 @@ class PolicyTests(unittest.TestCase):
self.assertIsNone(policy._local._loop)
def test_get_event_loop_does_not_call_set_event_loop(self):
- policy = asyncio._DefaultEventLoopPolicy()
+ policy = test_utils.DefaultEventLoopPolicy()
with mock.patch.object(
policy, "set_event_loop",
@@ -2869,7 +2869,7 @@ class PolicyTests(unittest.TestCase):
m_set_event_loop.assert_not_called()
def test_get_event_loop_after_set_none(self):
- policy = asyncio._DefaultEventLoopPolicy()
+ policy = test_utils.DefaultEventLoopPolicy()
policy.set_event_loop(None)
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 f():
- policy = asyncio._DefaultEventLoopPolicy()
+ policy = test_utils.DefaultEventLoopPolicy()
self.assertRaises(RuntimeError, policy.get_event_loop)
th = threading.Thread(target=f)
@@ -2885,14 +2885,14 @@ class PolicyTests(unittest.TestCase):
th.join()
def test_new_event_loop(self):
- policy = asyncio._DefaultEventLoopPolicy()
+ policy = test_utils.DefaultEventLoopPolicy()
loop = policy.new_event_loop()
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
loop.close()
def test_set_event_loop(self):
- policy = asyncio._DefaultEventLoopPolicy()
+ policy = test_utils.DefaultEventLoopPolicy()
old_loop = policy.new_event_loop()
policy.set_event_loop(old_loop)
@@ -2909,7 +2909,7 @@ class PolicyTests(unittest.TestCase):
with self.assertWarnsRegex(
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
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())
def test_set_event_loop_policy(self):
@@ -2922,7 +2922,7 @@ class PolicyTests(unittest.TestCase):
DeprecationWarning, "'asyncio.get_event_loop_policy' is deprecated"):
old_policy = asyncio.get_event_loop_policy()
- policy = asyncio._DefaultEventLoopPolicy()
+ policy = test_utils.DefaultEventLoopPolicy()
with self.assertWarnsRegex(
DeprecationWarning, "'asyncio.set_event_loop_policy' is deprecated"):
asyncio.set_event_loop_policy(policy)
@@ -3034,13 +3034,13 @@ class GetEventLoopTestsMixin:
class TestError(Exception):
pass
- class Policy(asyncio._DefaultEventLoopPolicy):
+ class Policy(test_utils.DefaultEventLoopPolicy):
def get_event_loop(self):
raise TestError
- old_policy = asyncio._get_event_loop_policy()
+ old_policy = asyncio.events._get_event_loop_policy()
try:
- asyncio._set_event_loop_policy(Policy())
+ asyncio.events._set_event_loop_policy(Policy())
loop = asyncio.new_event_loop()
with self.assertRaises(TestError):
@@ -3068,7 +3068,7 @@ class GetEventLoopTestsMixin:
asyncio.get_event_loop()
finally:
- asyncio._set_event_loop_policy(old_policy)
+ asyncio.events._set_event_loop_policy(old_policy)
if loop is not None:
loop.close()
@@ -3078,9 +3078,9 @@ class GetEventLoopTestsMixin:
self.assertIs(asyncio._get_running_loop(), None)
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:
- asyncio._set_event_loop_policy(asyncio._DefaultEventLoopPolicy())
+ asyncio.events._set_event_loop_policy(test_utils.DefaultEventLoopPolicy())
loop = asyncio.new_event_loop()
self.addCleanup(loop.close)
@@ -3106,7 +3106,7 @@ class GetEventLoopTestsMixin:
asyncio.get_event_loop()
finally:
- asyncio._set_event_loop_policy(old_policy)
+ asyncio.events._set_event_loop_policy(old_policy)
if loop is not None:
loop.close()
diff --git a/Lib/test/test_asyncio/test_free_threading.py b/Lib/test/test_asyncio/test_free_threading.py
index 110996c..d874ed0 100644
--- a/Lib/test/test_asyncio/test_free_threading.py
+++ b/Lib/test/test_asyncio/test_free_threading.py
@@ -15,7 +15,7 @@ class MyException(Exception):
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class TestFreeThreading:
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index 8b51522..785258a 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -17,7 +17,7 @@ from test import support
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def _fakefunc(f):
diff --git a/Lib/test/test_asyncio/test_futures2.py b/Lib/test/test_asyncio/test_futures2.py
index e2cddea..c7c0ebd 100644
--- a/Lib/test/test_asyncio/test_futures2.py
+++ b/Lib/test/test_asyncio/test_futures2.py
@@ -7,7 +7,7 @@ from asyncio import tasks
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class FutureTests:
diff --git a/Lib/test/test_asyncio/test_graph.py b/Lib/test/test_asyncio/test_graph.py
index 62f6593..2f22fbc 100644
--- a/Lib/test/test_asyncio/test_graph.py
+++ b/Lib/test/test_asyncio/test_graph.py
@@ -5,7 +5,7 @@ import unittest
# To prevent a warning "test altered the execution environment"
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def capture_test_stack(*, fut=None, depth=1):
diff --git a/Lib/test/test_asyncio/test_locks.py b/Lib/test/test_asyncio/test_locks.py
index 047f03c..e025d29 100644
--- a/Lib/test/test_asyncio/test_locks.py
+++ b/Lib/test/test_asyncio/test_locks.py
@@ -20,7 +20,7 @@ RGX_REPR = re.compile(STR_RGX_REPR)
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class LockTests(unittest.IsolatedAsyncioTestCase):
diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py
index 48f4a75..a0c8434 100644
--- a/Lib/test/test_asyncio/test_pep492.py
+++ b/Lib/test/test_asyncio/test_pep492.py
@@ -11,7 +11,7 @@ from test.test_asyncio import utils as test_utils
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index 24c4e85..b25daaf 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -18,7 +18,7 @@ from test.test_asyncio import utils as test_utils
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def close_transport(transport):
diff --git a/Lib/test/test_asyncio/test_protocols.py b/Lib/test/test_asyncio/test_protocols.py
index 4484a03..29d3bd2 100644
--- a/Lib/test/test_asyncio/test_protocols.py
+++ b/Lib/test/test_asyncio/test_protocols.py
@@ -7,7 +7,7 @@ import asyncio
def tearDownModule():
# not needed for the test file but added for uniformness with all other
# 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):
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py
index 090b977..54bbe79 100644
--- a/Lib/test/test_asyncio/test_queues.py
+++ b/Lib/test/test_asyncio/test_queues.py
@@ -6,7 +6,7 @@ from types import GenericAlias
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class QueueBasicTests(unittest.IsolatedAsyncioTestCase):
diff --git a/Lib/test/test_asyncio/test_runners.py b/Lib/test/test_asyncio/test_runners.py
index 21f277b..8a4d7f5 100644
--- a/Lib/test/test_asyncio/test_runners.py
+++ b/Lib/test/test_asyncio/test_runners.py
@@ -12,14 +12,14 @@ from unittest.mock import patch
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def interrupt_self():
_thread.interrupt_main()
-class TestPolicy(asyncio._AbstractEventLoopPolicy):
+class TestPolicy(asyncio.events._AbstractEventLoopPolicy):
def __init__(self, loop_factory):
self.loop_factory = loop_factory
@@ -61,15 +61,15 @@ class BaseTest(unittest.TestCase):
super().setUp()
policy = TestPolicy(self.new_loop)
- asyncio._set_event_loop_policy(policy)
+ asyncio.events._set_event_loop_policy(policy)
def tearDown(self):
- policy = asyncio._get_event_loop_policy()
+ policy = asyncio.events._get_event_loop_policy()
if policy.loop is not None:
self.assertTrue(policy.loop.is_closed())
self.assertTrue(policy.loop.shutdown_ag_run)
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
super().tearDown()
@@ -208,7 +208,7 @@ class RunTests(BaseTest):
await asyncio.sleep(0)
return 42
- policy = asyncio._get_event_loop_policy()
+ policy = asyncio.events._get_event_loop_policy()
policy.set_event_loop = mock.Mock()
asyncio.run(main())
self.assertTrue(policy.set_event_loop.called)
@@ -259,7 +259,7 @@ class RunTests(BaseTest):
loop.set_task_factory(Task)
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):
asyncio.run(main())
@@ -495,7 +495,7 @@ class RunnerTests(BaseTest):
async def coro():
pass
- policy = asyncio._get_event_loop_policy()
+ policy = asyncio.events._get_event_loop_policy()
policy.set_event_loop = mock.Mock()
runner = asyncio.Runner()
runner.run(coro())
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
index aab6a77..7b6d1bc 100644
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -24,7 +24,7 @@ MOCK_ANY = mock.ANY
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py
index e1b766d..dcd963b 100644
--- a/Lib/test/test_asyncio/test_sendfile.py
+++ b/Lib/test/test_asyncio/test_sendfile.py
@@ -22,7 +22,7 @@ except ImportError:
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class MySendfileProto(asyncio.Protocol):
diff --git a/Lib/test/test_asyncio/test_server.py b/Lib/test/test_asyncio/test_server.py
index 32211f4..5bd0f7e 100644
--- a/Lib/test/test_asyncio/test_server.py
+++ b/Lib/test/test_asyncio/test_server.py
@@ -11,7 +11,7 @@ from test.test_asyncio import functional as func_tests
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class BaseStartServer(func_tests.FunctionalTestCaseMixin):
diff --git a/Lib/test/test_asyncio/test_sock_lowlevel.py b/Lib/test/test_asyncio/test_sock_lowlevel.py
index 4f7b9a1..df4ec79 100644
--- a/Lib/test/test_asyncio/test_sock_lowlevel.py
+++ b/Lib/test/test_asyncio/test_sock_lowlevel.py
@@ -15,7 +15,7 @@ if socket_helper.tcp_blackhole():
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class MyProto(asyncio.Protocol):
diff --git a/Lib/test/test_asyncio/test_ssl.py b/Lib/test/test_asyncio/test_ssl.py
index 3a7185c..06118f3 100644
--- a/Lib/test/test_asyncio/test_ssl.py
+++ b/Lib/test/test_asyncio/test_ssl.py
@@ -30,7 +30,7 @@ BUF_MULTIPLIER = 1024 if not MACOS else 64
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class MyBaseProto(asyncio.Protocol):
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
index aa248c5..3e304c1 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -21,7 +21,7 @@ from test.test_asyncio import functional as func_tests
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
@unittest.skipIf(ssl is None, 'No ssl module')
diff --git a/Lib/test/test_asyncio/test_staggered.py b/Lib/test/test_asyncio/test_staggered.py
index ad34aa6..32e4817 100644
--- a/Lib/test/test_asyncio/test_staggered.py
+++ b/Lib/test/test_asyncio/test_staggered.py
@@ -8,7 +8,7 @@ support.requires_working_socket(module=True)
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class StaggeredTests(unittest.IsolatedAsyncioTestCase):
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 4fa4384..f93ee54 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -18,7 +18,7 @@ from test.support import socket_helper
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class StreamTests(test_utils.TestCase):
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 341e3e9..3a17c16 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -37,7 +37,7 @@ PROGRAM_CAT = [
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class TestSubprocessTransport(base_subprocess.BaseSubprocessTransport):
diff --git a/Lib/test/test_asyncio/test_taskgroups.py b/Lib/test/test_asyncio/test_taskgroups.py
index 0d69a43..91f6b03 100644
--- a/Lib/test/test_asyncio/test_taskgroups.py
+++ b/Lib/test/test_asyncio/test_taskgroups.py
@@ -15,7 +15,7 @@ from test.test_asyncio.utils import await_without_task
# To prevent a warning "test altered the execution environment"
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class MyExc(Exception):
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index f6f976f..931a438 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -24,7 +24,7 @@ from test.support.warnings_helper import ignore_warnings
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
async def coroutine_function():
diff --git a/Lib/test/test_asyncio/test_threads.py b/Lib/test/test_asyncio/test_threads.py
index c98c9a9..8ad5f9b 100644
--- a/Lib/test/test_asyncio/test_threads.py
+++ b/Lib/test/test_asyncio/test_threads.py
@@ -8,7 +8,7 @@ from unittest import mock
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class ToThreadTests(unittest.IsolatedAsyncioTestCase):
diff --git a/Lib/test/test_asyncio/test_timeouts.py b/Lib/test/test_asyncio/test_timeouts.py
index 3ba84d6..f60722c 100644
--- a/Lib/test/test_asyncio/test_timeouts.py
+++ b/Lib/test/test_asyncio/test_timeouts.py
@@ -9,7 +9,7 @@ from test.test_asyncio.utils import await_without_task
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class TimeoutTests(unittest.IsolatedAsyncioTestCase):
diff --git a/Lib/test/test_asyncio/test_transports.py b/Lib/test/test_asyncio/test_transports.py
index af10d3d..dbb572e 100644
--- a/Lib/test/test_asyncio/test_transports.py
+++ b/Lib/test/test_asyncio/test_transports.py
@@ -10,7 +10,7 @@ from asyncio import transports
def tearDownModule():
# not needed for the test file but added for uniformness with all other
# 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):
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index e020c1f..22982dc 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -30,7 +30,7 @@ from test.test_asyncio import utils as test_utils
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
MOCK_ANY = mock.ANY
diff --git a/Lib/test/test_asyncio/test_waitfor.py b/Lib/test/test_asyncio/test_waitfor.py
index d083f6b..dedc6bf 100644
--- a/Lib/test/test_asyncio/test_waitfor.py
+++ b/Lib/test/test_asyncio/test_waitfor.py
@@ -5,7 +5,7 @@ from test import support
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:
diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py
index 69e9905..0af3368 100644
--- a/Lib/test/test_asyncio/test_windows_events.py
+++ b/Lib/test/test_asyncio/test_windows_events.py
@@ -19,7 +19,7 @@ from test.test_asyncio import utils as test_utils
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class UpperProto(asyncio.Protocol):
@@ -330,16 +330,16 @@ class WinPolicyTests(WindowsEventsTestCase):
async def main():
self.assertIsInstance(asyncio.get_running_loop(), asyncio.SelectorEventLoop)
- old_policy = asyncio._get_event_loop_policy()
+ old_policy = asyncio.events._get_event_loop_policy()
try:
with self.assertWarnsRegex(
DeprecationWarning,
"'asyncio.WindowsSelectorEventLoopPolicy' is deprecated",
):
- asyncio._set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
+ asyncio.events._set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())
finally:
- asyncio._set_event_loop_policy(old_policy)
+ asyncio.events._set_event_loop_policy(old_policy)
def test_proactor_win_policy(self):
async def main():
@@ -347,16 +347,16 @@ class WinPolicyTests(WindowsEventsTestCase):
asyncio.get_running_loop(),
asyncio.ProactorEventLoop)
- old_policy = asyncio._get_event_loop_policy()
+ old_policy = asyncio.events._get_event_loop_policy()
try:
with self.assertWarnsRegex(
DeprecationWarning,
"'asyncio.WindowsProactorEventLoopPolicy' is deprecated",
):
- asyncio._set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
+ asyncio.events._set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
asyncio.run(main())
finally:
- asyncio._set_event_loop_policy(old_policy)
+ asyncio.events._set_event_loop_policy(old_policy)
if __name__ == '__main__':
diff --git a/Lib/test/test_asyncio/test_windows_utils.py b/Lib/test/test_asyncio/test_windows_utils.py
index a6b2075..97f078f 100644
--- a/Lib/test/test_asyncio/test_windows_utils.py
+++ b/Lib/test/test_asyncio/test_windows_utils.py
@@ -16,7 +16,7 @@ from test import support
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class PipeTests(unittest.TestCase):
diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index 0a96573..a480e16 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -601,3 +601,9 @@ async def await_without_task(coro):
await asyncio.sleep(0)
if exc is not None:
raise exc
+
+
+if sys.platform == 'win32':
+ DefaultEventLoopPolicy = asyncio.windows_events._DefaultEventLoopPolicy
+else:
+ DefaultEventLoopPolicy = asyncio.unix_events._DefaultEventLoopPolicy
diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py b/Lib/test/test_concurrent_futures/test_interpreter_pool.py
index b10bbeb..d5c032d 100644
--- a/Lib/test/test_concurrent_futures/test_interpreter_pool.py
+++ b/Lib/test/test_concurrent_futures/test_interpreter_pool.py
@@ -512,7 +512,7 @@ class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):
# tests left a policy in place, just in case.
policy = support.maybe_get_event_loop_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):
super().setUp()
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index 954003a..a515e0f 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -2337,7 +2337,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
pass
finally:
loop.close()
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
self.assertEqual(buffer, [1, 2, 'MyException'])
diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py
index 5e1fcc1..55942c2 100644
--- a/Lib/test/test_inspect/test_inspect.py
+++ b/Lib/test/test_inspect/test_inspect.py
@@ -2820,7 +2820,7 @@ class TestGetAsyncGenState(unittest.IsolatedAsyncioTestCase):
@classmethod
def tearDownClass(cls):
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
def _asyncgenstate(self):
return inspect.getasyncgenstate(self.asyncgen)
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index c46e6f8..d8d1020 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -5421,7 +5421,7 @@ class LogRecordTest(BaseTest):
logging.logAsyncioTasks = False
runner.run(make_record(self.assertIsNone))
finally:
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
@support.requires_working_socket()
def test_taskName_without_asyncio_imported(self):
@@ -5433,7 +5433,7 @@ class LogRecordTest(BaseTest):
logging.logAsyncioTasks = False
runner.run(make_record(self.assertIsNone))
finally:
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class BasicConfigTest(unittest.TestCase):
@@ -5737,7 +5737,7 @@ class BasicConfigTest(unittest.TestCase):
data = f.read().strip()
self.assertRegex(data, r'Task-\d+ - hello world')
finally:
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
if handler:
handler.close()
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 5217037..1e50dc4 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -104,7 +104,7 @@ requires_splice_pipe = unittest.skipIf(sys.platform.startswith("aix"),
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class MiscTests(unittest.TestCase):
diff --git a/Lib/test/test_unittest/test_async_case.py b/Lib/test/test_unittest/test_async_case.py
index 993e6bf..91d4528 100644
--- a/Lib/test/test_unittest/test_async_case.py
+++ b/Lib/test/test_unittest/test_async_case.py
@@ -12,7 +12,7 @@ class MyException(Exception):
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class TestCM:
@@ -480,7 +480,7 @@ class TestAsyncCase(unittest.TestCase):
class TestCase1(unittest.IsolatedAsyncioTestCase):
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):
pass
@@ -490,7 +490,7 @@ class TestAsyncCase(unittest.TestCase):
self.assertTrue(result.wasSuccessful())
def test_loop_factory(self):
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class TestCase1(unittest.IsolatedAsyncioTestCase):
loop_factory = asyncio.EventLoop
diff --git a/Lib/test/test_unittest/testmock/testasync.py b/Lib/test/test_unittest/testmock/testasync.py
index 0791675..dc36cee 100644
--- a/Lib/test/test_unittest/testmock/testasync.py
+++ b/Lib/test/test_unittest/testmock/testasync.py
@@ -15,7 +15,7 @@ from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock, Mock,
def tearDownModule():
- asyncio._set_event_loop_policy(None)
+ asyncio.events._set_event_loop_policy(None)
class AsyncClass:
diff --git a/Misc/NEWS.d/next/Library/2025-05-25-11-02-05.gh-issue-134657.3YFhR9.rst b/Misc/NEWS.d/next/Library/2025-05-25-11-02-05.gh-issue-134657.3YFhR9.rst
new file mode 100644
index 0000000..1bf8ee5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-05-25-11-02-05.gh-issue-134657.3YFhR9.rst
@@ -0,0 +1 @@
+:mod:`asyncio`: Remove some private names from ``asyncio.__all__``.