From 01ba75cacf257a49b1e2a4feb7ebd08c194d8864 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 28 Nov 2017 11:29:23 +0100 Subject: [PATCH 1/2] bpo-32154: Remove asyncio.selectors * Remove asyncio.selectors and asyncio._overlapped symbols from the namespace of the asyncio module * Replace "from asyncio import selectors" with "import selectors" * Replace "from asyncio import _overlapped" with "import _overlapped" asyncio.selectors was added to support Python 3.3, which doesn't have selectors in its standard library, and Python 3.4 in the same code base. Same rationale for asyncio._overlapped. Python 3.3 reached its end of life, and asyncio is no more maintained as a third party module on PyPI. --- Doc/whatsnew/3.7.rst | 4 ++++ Lib/asyncio/__init__.py | 15 --------------- Lib/asyncio/selector_events.py | 2 +- Lib/asyncio/test_utils.py | 2 +- Lib/asyncio/unix_events.py | 2 +- Lib/asyncio/windows_events.py | 2 +- Lib/test/test_asyncio/test_events.py | 2 +- Lib/test/test_asyncio/test_selector_events.py | 2 +- Lib/test/test_asyncio/test_windows_events.py | 2 +- Lib/test/test_asyncio/test_windows_utils.py | 2 +- 10 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 514c3c293c080c..99c0d0e9035940 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -677,6 +677,10 @@ Changes in Python behavior Changes in the Python API ------------------------- +* :mod:`asyncio`: The module doesn't export :mod:`selectors` and `_overlapped` + modules as ``asyncio.selectors`` and ``asyncio._overlapped``. Replace + ``from asyncio import selectors`` with ``import selectors`` for example. + * :meth:`pkgutil.walk_packages` now raises ValueError if *path* is a string. Previously an empty list was returned. (Contributed by Sanyam Khurana in :issue:`24744`.) diff --git a/Lib/asyncio/__init__.py b/Lib/asyncio/__init__.py index 011466b3e0dc8f..1ee1b2516d459c 100644 --- a/Lib/asyncio/__init__.py +++ b/Lib/asyncio/__init__.py @@ -2,21 +2,6 @@ import sys -# The selectors module is in the stdlib in Python 3.4 but not in 3.3. -# Do this first, so the other submodules can use "from . import selectors". -# Prefer asyncio/selectors.py over the stdlib one, as ours may be newer. -try: - from . import selectors -except ImportError: - import selectors # Will also be exported. - -if sys.platform == 'win32': - # Similar thing for _overlapped. - try: - from . import _overlapped - except ImportError: - import _overlapped # Will also be exported. - # This relies on each of the submodules having an __all__ variable. from .base_events import * from .coroutines import * diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index ef6f0ac458d41b..3639466f6c2bb9 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -9,6 +9,7 @@ import collections import errno import functools +import selectors import socket import warnings import weakref @@ -21,7 +22,6 @@ from . import constants from . import events from . import futures -from . import selectors from . import transports from . import sslproto from .coroutines import coroutine diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py index c3ddfe37563a6a..f797b2f0bed481 100644 --- a/Lib/asyncio/test_utils.py +++ b/Lib/asyncio/test_utils.py @@ -6,6 +6,7 @@ import logging import os import re +import selectors import socket import socketserver import sys @@ -28,7 +29,6 @@ from . import base_events from . import events from . import futures -from . import selectors from . import tasks from .coroutines import coroutine from .log import logger diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 94157f8c8094ca..06bcdcc5ed1c8d 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -2,6 +2,7 @@ import errno import os +import selectors import signal import socket import stat @@ -18,7 +19,6 @@ from . import events from . import futures from . import selector_events -from . import selectors from . import transports from .coroutines import coroutine from .log import logger diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py index 031e3f1874eae5..de41e645163dcc 100644 --- a/Lib/asyncio/windows_events.py +++ b/Lib/asyncio/windows_events.py @@ -1,5 +1,6 @@ """Selector and proactor event loops for Windows.""" +import _overlapped import _winapi import errno import math @@ -14,7 +15,6 @@ from . import selector_events from . import tasks from . import windows_utils -from . import _overlapped from .coroutines import coroutine from .log import logger diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index a6e4ecf7958df7..c252a4c01e341d 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -2141,7 +2141,7 @@ def test_create_datagram_endpoint(self): def test_remove_fds_after_closing(self): raise unittest.SkipTest("IocpEventLoop does not have add_reader()") else: - from asyncio import selectors + import selectors class UnixEventLoopTestsMixin(EventLoopTestsMixin): def setUp(self): diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py index 7db943e8009627..616eb6f2630503 100644 --- a/Lib/test/test_asyncio/test_selector_events.py +++ b/Lib/test/test_asyncio/test_selector_events.py @@ -1,6 +1,7 @@ """Tests for selector_events.py""" import errno +import selectors import socket import unittest from unittest import mock @@ -10,7 +11,6 @@ ssl = None import asyncio -from asyncio import selectors from asyncio import test_utils from asyncio.selector_events import BaseSelectorEventLoop from asyncio.selector_events import _SelectorTransport diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index b70c0b7ebb82ee..5fdf5ff5e440ae 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -7,10 +7,10 @@ if sys.platform != 'win32': raise unittest.SkipTest('Windows only') +import _overlapped import _winapi import asyncio -from asyncio import _overlapped from asyncio import test_utils from asyncio import windows_events diff --git a/Lib/test/test_asyncio/test_windows_utils.py b/Lib/test/test_asyncio/test_windows_utils.py index d48b8bcbb0874f..4fddaa25895391 100644 --- a/Lib/test/test_asyncio/test_windows_utils.py +++ b/Lib/test/test_asyncio/test_windows_utils.py @@ -9,9 +9,9 @@ if sys.platform != 'win32': raise unittest.SkipTest('Windows only') +import _overlapped import _winapi -from asyncio import _overlapped from asyncio import windows_utils try: from test import support From 5a9346426dce880e0f02f964a3accb81983e9919 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 28 Nov 2017 14:47:58 +0100 Subject: [PATCH 2/2] Fix Sphinx syntax in What's New in Python 3.7 --- Doc/whatsnew/3.7.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 99c0d0e9035940..a67cbc1576f0e3 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -677,9 +677,10 @@ Changes in Python behavior Changes in the Python API ------------------------- -* :mod:`asyncio`: The module doesn't export :mod:`selectors` and `_overlapped` - modules as ``asyncio.selectors`` and ``asyncio._overlapped``. Replace - ``from asyncio import selectors`` with ``import selectors`` for example. +* :mod:`asyncio`: The module doesn't export :mod:`selectors` and + :mod:`_overlapped` modules as ``asyncio.selectors`` and + ``asyncio._overlapped``. Replace ``from asyncio import selectors`` with + ``import selectors`` for example. * :meth:`pkgutil.walk_packages` now raises ValueError if *path* is a string. Previously an empty list was returned. (Contributed by Sanyam Khurana in