Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 128ee22

Browse files
committed
asyncio: Don't export BaseEventLoop, BaseSelectorEventLoop nor
BaseProactorEventLoop Import them from submodules if you really need them.
1 parent ce8d153 commit 128ee22

5 files changed

Lines changed: 13 additions & 15 deletions

File tree

Lib/asyncio/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
import _overlapped # Will also be exported.
1919

2020
# This relies on each of the submodules having an __all__ variable.
21-
from .base_events import *
2221
from .events import *
2322
from .futures import *
2423
from .locks import *
25-
from .proactor_events import *
2624
from .protocols import *
2725
from .queues import *
28-
from .selector_events import *
2926
from .streams import *
3027
from .tasks import *
3128
from .transports import *
@@ -36,14 +33,11 @@
3633
from .unix_events import * # pragma: no cover
3734

3835

39-
__all__ = (base_events.__all__ +
40-
events.__all__ +
36+
__all__ = (events.__all__ +
4137
futures.__all__ +
4238
locks.__all__ +
43-
proactor_events.__all__ +
4439
protocols.__all__ +
4540
queues.__all__ +
46-
selector_events.__all__ +
4741
streams.__all__ +
4842
tasks.__all__ +
4943
transports.__all__)

Lib/test/test_asyncio/test_base_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
from test.support import find_unused_port, IPV6_ENABLED
1010

1111
import asyncio
12+
from asyncio import base_events
1213
from asyncio import constants
1314
from asyncio import test_utils
1415

1516

1617
class BaseEventLoopTests(unittest.TestCase):
1718

1819
def setUp(self):
19-
self.loop = asyncio.BaseEventLoop()
20+
self.loop = base_events.BaseEventLoop()
2021
self.loop._selector = unittest.mock.Mock()
2122
asyncio.set_event_loop(None)
2223

Lib/test/test_asyncio/test_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import asyncio
2727
from asyncio import events
28+
from asyncio import selector_events
2829
from asyncio import test_utils
2930

3031

@@ -902,7 +903,7 @@ def datagram_received(self, data, addr):
902903

903904
def test_internal_fds(self):
904905
loop = self.create_event_loop()
905-
if not isinstance(loop, asyncio.BaseSelectorEventLoop):
906+
if not isinstance(loop, selector_events.BaseSelectorEventLoop):
906907
self.skipTest('loop is not a BaseSelectorEventLoop')
907908

908909
self.assertEqual(1, loop._internal_fds)

Lib/test/test_asyncio/test_proactor_events.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest.mock
66

77
import asyncio
8+
from asyncio.proactor_events import BaseProactorEventLoop
89
from asyncio.proactor_events import _ProactorSocketTransport
910
from asyncio.proactor_events import _ProactorWritePipeTransport
1011
from asyncio.proactor_events import _ProactorDuplexPipeTransport
@@ -344,18 +345,18 @@ def setUp(self):
344345

345346
self.ssock, self.csock = unittest.mock.Mock(), unittest.mock.Mock()
346347

347-
class EventLoop(asyncio.BaseProactorEventLoop):
348+
class EventLoop(BaseProactorEventLoop):
348349
def _socketpair(s):
349350
return (self.ssock, self.csock)
350351

351352
self.loop = EventLoop(self.proactor)
352353

353-
@unittest.mock.patch.object(asyncio.BaseProactorEventLoop, 'call_soon')
354-
@unittest.mock.patch.object(asyncio.BaseProactorEventLoop, '_socketpair')
354+
@unittest.mock.patch.object(BaseProactorEventLoop, 'call_soon')
355+
@unittest.mock.patch.object(BaseProactorEventLoop, '_socketpair')
355356
def test_ctor(self, socketpair, call_soon):
356357
ssock, csock = socketpair.return_value = (
357358
unittest.mock.Mock(), unittest.mock.Mock())
358-
loop = asyncio.BaseProactorEventLoop(self.proactor)
359+
loop = BaseProactorEventLoop(self.proactor)
359360
self.assertIs(loop._ssock, ssock)
360361
self.assertIs(loop._csock, csock)
361362
self.assertEqual(loop._internal_fds, 1)
@@ -398,7 +399,7 @@ def test_sock_accept(self):
398399

399400
def test_socketpair(self):
400401
self.assertRaises(
401-
NotImplementedError, asyncio.BaseProactorEventLoop, self.proactor)
402+
NotImplementedError, BaseProactorEventLoop, self.proactor)
402403

403404
def test_make_socket_transport(self):
404405
tr = self.loop._make_socket_transport(self.sock, unittest.mock.Mock())

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
import asyncio
1717
from asyncio import selectors
1818
from asyncio import test_utils
19+
from asyncio.selector_events import BaseSelectorEventLoop
1920
from asyncio.selector_events import _SelectorTransport
2021
from asyncio.selector_events import _SelectorSslTransport
2122
from asyncio.selector_events import _SelectorSocketTransport
2223
from asyncio.selector_events import _SelectorDatagramTransport
2324

2425

25-
class TestBaseSelectorEventLoop(asyncio.BaseSelectorEventLoop):
26+
class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
2627

2728
def _make_self_pipe(self):
2829
self._ssock = unittest.mock.Mock()

0 commit comments

Comments
 (0)