[Python-checkins] cpython (merge 3.4 -> default): (Merge 3.4) asyncio: Move loop attribute to _FlowControlMixin

victor.stinner python-checkins at python.org
Wed Nov 5 15:31:30 CET 2014


https://hg.python.org/cpython/rev/b9ee2082256d
changeset:   93389:b9ee2082256d
parent:      93387:d6fb87972dee
parent:      93388:d05ba48cfc29
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Nov 05 15:27:54 2014 +0100
summary:
  (Merge 3.4) asyncio: Move loop attribute to _FlowControlMixin

Move the _loop attribute from the constructor of _SelectorTransport,
_ProactorBasePipeTransport and _UnixWritePipeTransport classes to the
constructor of the _FlowControlMixin class.

Add also an assertion to explicit that the parent class must ensure that the
loop is defined (not None)

files:
  Lib/asyncio/proactor_events.py           |  3 +--
  Lib/asyncio/selector_events.py           |  3 +--
  Lib/asyncio/transports.py                |  4 +++-
  Lib/asyncio/unix_events.py               |  3 +--
  Lib/test/test_asyncio/test_transports.py |  3 ++-
  5 files changed, 8 insertions(+), 8 deletions(-)


diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -21,9 +21,8 @@
 
     def __init__(self, loop, sock, protocol, waiter=None,
                  extra=None, server=None):
-        super().__init__(extra)
+        super().__init__(extra, loop)
         self._set_extra(sock)
-        self._loop = loop
         self._sock = sock
         self._protocol = protocol
         self._server = server
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -447,7 +447,7 @@
     _buffer_factory = bytearray  # Constructs initial value for self._buffer.
 
     def __init__(self, loop, sock, protocol, extra, server=None):
-        super().__init__(extra)
+        super().__init__(extra, loop)
         self._extra['socket'] = sock
         self._extra['sockname'] = sock.getsockname()
         if 'peername' not in self._extra:
@@ -455,7 +455,6 @@
                 self._extra['peername'] = sock.getpeername()
             except socket.error:
                 self._extra['peername'] = None
-        self._loop = loop
         self._sock = sock
         self._sock_fd = sock.fileno()
         self._protocol = protocol
diff --git a/Lib/asyncio/transports.py b/Lib/asyncio/transports.py
--- a/Lib/asyncio/transports.py
+++ b/Lib/asyncio/transports.py
@@ -238,8 +238,10 @@
     resume_writing() may be called.
     """
 
-    def __init__(self, extra=None):
+    def __init__(self, extra=None, loop=None):
         super().__init__(extra)
+        assert loop is not None
+        self._loop = loop
         self._protocol_paused = False
         self._set_write_buffer_limits()
 
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -369,9 +369,8 @@
                               transports.WriteTransport):
 
     def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
-        super().__init__(extra)
+        super().__init__(extra, loop)
         self._extra['pipe'] = pipe
-        self._loop = loop
         self._pipe = pipe
         self._fileno = pipe.fileno()
         mode = os.fstat(self._fileno).st_mode
diff --git a/Lib/test/test_asyncio/test_transports.py b/Lib/test/test_asyncio/test_transports.py
--- a/Lib/test/test_asyncio/test_transports.py
+++ b/Lib/test/test_asyncio/test_transports.py
@@ -69,7 +69,8 @@
             def get_write_buffer_size(self):
                 return 512
 
-        transport = MyTransport()
+        loop = mock.Mock()
+        transport = MyTransport(loop=loop)
         transport._protocol = mock.Mock()
 
         self.assertFalse(transport._protocol_paused)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list