10000 bpo-42392: Remove loop parameter from asyncio.streams (GH-23517) · Ringdingcoder/cpython@f533cb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f533cb8

Browse files
authored
bpo-42392: Remove loop parameter from asyncio.streams (pythonGH-23517)
1 parent 87f7ab5 commit f533cb8

File tree

6 files changed

+56
-109
lines changed

6 files changed

+56
-109
lines changed

Lib/asyncio/streams.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
async def open_connection(host=None, port=None, *,
26-
loop=None, limit=_DEFAULT_LIMIT, **kwds):
26+
limit=_DEFAULT_LIMIT, **kwds):
2727
"""A wrapper for create_connection() returning a (reader, writer) pair.
2828
2929
The reader returned is a StreamReader instance; the writer is a
@@ -41,12 +41,7 @@ async def open_connection(host=None, port=None, *,
4141
StreamReaderProtocol classes, just copy the code -- there's
4242
really nothing special here except some convenience.)
4343
"""
44-
if loop is None:
45-
loop = events.get_event_loop()
46-
else:
47-
warnings.warn("The loop argument is deprecated since Python 3.8, "
48-
"and scheduled for removal in Python 3.10.",
49-
DeprecationWarning, stacklevel=2)
44+
loop = events.get_running_loop()
5045
reader = StreamReader(limit=limit, loop=loop)
5146
protocol = StreamReaderProtocol(reader, loop=loop)
5247
transport, _ = await loop.create_connection(
@@ -56,7 +51,7 @@ async def open_connection(host=None, port=None, *,
5651

5752

5853
async def start_server(client_connected_cb, host=None, port=None, *,
59-
loop=None, limit=_DEFAULT_LIMIT, **kwds):
54+
limit=_DEFAULT_LIMIT, **kwds):
6055
"""Start a socket server, call back for each client connected.
6156
6257
The first parameter, `client_connected_cb`, takes two parameters:
@@ -78,12 +73,7 @@ async def start_server(client_connected_cb, host=None, port=None, *,
7873
The return value is the same as loop.create_server(), i.e. a
7974
Server object which can be used to stop the service.
8075
"""
81-
if loop is None:
82-
loop = events.get_event_loop()
83-
else:
84-
warnings.warn("The loop argument is deprecated since Python 3.8, "
85-
"and scheduled for removal in Python 3.10.",
86-
DeprecationWarning, stacklevel=2)
76+
loop = events.get_running_loop()
8777

8878
def factory():
8979
reader = StreamReader(limit=limit, loop=loop)
@@ -98,14 +88,10 @@ def factory():
9888
# UNIX Domain Sockets are supported on this platform
9989

10090
async def open_unix_connection(path=None, *,
101-
loop=None, limit=_DEFAULT_LIMIT, **kwds):
91+
limit=_DEFAULT_LIMIT, **kwds):
10292
"""Similar to `open_connection` but works with UNIX Domain Sockets."""
103-
if loop is None:
104-
loop = events.get_event_loop()
105-
else:
106-
warnings.warn("The loop argument is deprecated since Python 3.8, "
107-
"and scheduled for removal in Python 3.10.",
108-
DeprecationWarning, stacklevel=2)
93+
loop = events.get_running_loop()
94+
10995
reader = StreamReader(limit=limit, loop=loop)
11096
protocol = StreamReaderProtocol(reader, loop=loop)
11197
transport, _ = await loop.create_unix_connection(
@@ -114,14 +100,9 @@ async def open_unix_connection(path=None, *,
114100
return reader, writer
115101

116102
async def start_unix_server(client_connected_cb, path=None, *,
117-
loop=None, limit=_DEFAULT_LIMIT, **kwds):
103+
limit=_DEFAULT_LIMIT, **kwds):
118104
"""Similar to `start_server` but works with UNIX Domain Sockets."""
119-
if loop is None:
120-
loop = events.get_event_loop()
121-
else:
122-
warnings.warn("The loop argument is deprecated since Python 3.8, "
123-
"and scheduled for removal in Python 3.10.",
124-
DeprecationWarning, stacklevel=2)
105+
loop = events.get_running_loop()
125106

126107
def factory():
127108
reader = StreamReader(limit=limit, loop=loop)

Lib/test/test_asyncio/test_base_events.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,7 @@ def test_create_server_stream_bittype(self):
11601160
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'no IPv6 support')
11611161
def test_create_server_ipv6(self):
11621162
async def main():
1163-
with self.assertWarns(DeprecationWarning):
1164-
srv = await asyncio.start_server(
1165-
lambda: None, '::1', 0, loop=self.loop)
1163+
srv = await asyncio.start_server(lambda: None, '::1', 0)
11661164
try:
11671165
self.assertGreater(len(srv.sockets), 0)
11681166
finally:

Lib/test/test_asyncio/test_server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ async def main(srv):
4545
async with srv:
4646
await srv.serve_forever()
4747

48-
with self.assertWarns(DeprecationWarning):
49-
srv = self.loop.run_until_complete(asyncio.start_server(
50-
serve, socket_helper.HOSTv4, 0, loop=self.loop, start_serving=False))
48+
srv = self.loop.run_until_complete(asyncio.start_server(
49+
serve, socket_helper.HOSTv4, 0, start_serving=False))
5150

5251
self.assertFalse(srv.is_serving())
5352

@@ -102,9 +101,8 @@ async def main(srv):
102101
await srv.serve_forever()
103102

104103
with test_utils.unix_socket_path() as addr:
105-
with self.assertWarns(DeprecationWarning):
106-
srv = self.loop.run_until_complete(asyncio.start_unix_server(
107-
serve, addr, loop=self.loop, start_serving=False))
104+
srv = self.loop.run_until_complete(asyncio.start_unix_server(
105+
serve, addr, start_serving=False))
108106

109107
main_task = self.loop.create_task(main(srv))
110108

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,11 @@ def server(sock):
657657
sock.close()
658658

659659
async def client(addr):
660-
with self.assertWarns(DeprecationWarning):
661-
reader, writer = await asyncio.open_connection(
662-
*addr,
663-
ssl=client_sslctx,
664-
server_hostname='',
665-
loop=self.loop,
666-
ssl_handshake_timeout=1.0)
660+
reader, writer = await asyncio.open_connection(
661+
*addr,
662+
ssl=client_sslctx,
663+
server_hostname='',
664+
ssl_handshake_timeout=1.0)
667665

668666
with self.tcp_server(server,
669667
max_clients=1,
@@ -697,13 +695,11 @@ def server(sock):
697695
sock.close()
698696

699697
async def client(addr):
700-
with self.assertWarns(DeprecationWarning):
701-
reader, writer = await asyncio.open_connection(
702-
*addr,
703-
ssl=client_sslctx,
704-
server_hostname='',
705-
loop=self.loop,
706-
ssl_handshake_timeout=support.LOOPBACK_TIMEOUT)
698+
reader, writer = await asyncio.open_connection(
699+
*addr,
700+
ssl=client_sslctx,
701+
server_hostname='',
702+
ssl_handshake_timeout=support.LOOPBACK_TIMEOUT)
707703

708704
with self.tcp_server(server,
709705
max_clients=1,
@@ -734,12 +730,10 @@ def server(sock):
734730
sock.close()
735731

736732
async def client(addr):
737-
with self.assertWarns(DeprecationWarning):
738-
reader, writer = await asyncio.open_connection(
739-
*addr,
740-
ssl=client_sslctx,
741-
server_hostname='',
742-
loop=self.loop)
733+
reader, writer = await asyncio.open_connection(
734+
*addr,
735+
ssl=client_sslctx,
736+
server_hostname='')
743737

744738
self.assertEqual(await reader.readline(), b'A\n')
745739
writer.write(b'B')

0 commit comments

Comments
 (0)
0