[Python-checkins] bpo-38178: Don't explicitly pass "loop" to EchoClientProtocol. (GH-16159)

Miss Islington (bot) webhook-mailer at python.org
Sun Sep 15 13:13:38 EDT 2019


https://github.com/python/cpython/commit/1cd6e926d30552056457820a682c1c361ee0f3ff
commit: 1cd6e926d30552056457820a682c1c361ee0f3ff
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-09-15T10:13:34-07:00
summary:

bpo-38178: Don't explicitly pass "loop" to EchoClientProtocol. (GH-16159)


https://bugs.python.org/issue38178
(cherry picked from commit c717c73fa33a2f3591442059eaf6e7a673e2c725)

Co-authored-by: Hrvoje Nikšić <hniksic at gmail.com>

files:
M Doc/library/asyncio-protocol.rst

diff --git a/Doc/library/asyncio-protocol.rst b/Doc/library/asyncio-protocol.rst
index 3e5a4dd8b891..ca37581c288d 100644
--- a/Doc/library/asyncio-protocol.rst
+++ b/Doc/library/asyncio-protocol.rst
@@ -767,9 +767,8 @@ data, and waits until the connection is closed::
 
 
     class EchoClientProtocol(asyncio.Protocol):
-        def __init__(self, message, on_con_lost, loop):
+        def __init__(self, message, on_con_lost):
             self.message = message
-            self.loop = loop
             self.on_con_lost = on_con_lost
 
         def connection_made(self, transport):
@@ -869,11 +868,10 @@ method, sends data and closes the transport when it receives the answer::
 
 
     class EchoClientProtocol:
-        def __init__(self, message, loop):
+        def __init__(self, message, on_con_lost):
             self.message = message
-            self.loop = loop
             self.transport = None
-            self.on_con_lost = loop.create_future()
+            self.on_con_lost = on_con_lost
 
         def connection_made(self, transport):
             self.transport = transport
@@ -899,13 +897,15 @@ method, sends data and closes the transport when it receives the answer::
         # low-level APIs.
         loop = asyncio.get_running_loop()
 
+        on_con_lost = loop.create_future()
         message = "Hello World!"
+
         transport, protocol = await loop.create_datagram_endpoint(
-            lambda: EchoClientProtocol(message, loop),
+            lambda: EchoClientProtocol(message, on_con_lost),
             remote_addr=('127.0.0.1', 9999))
 
         try:
-            await protocol.on_con_lost
+            await on_con_lost
         finally:
             transport.close()
 



More information about the Python-checkins mailing list