prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Fixed ConnectionsPool.[pubsub_channels/pubsub_patterns]
  Fixed bug in `commands.pubsub.PubSubCommandsMixin.subscribe` (and psubscribe). `ConnectionsPool.pubsub_channles` code was called before `ConnectionsPool._pubsub_conn` creation, and therefore `pubsub_channles` 
  
  </issue>
  <code>
  [start of aioredis/commands/pubsub.py]
  1 import json
  2 
  3 from aioredis.util import wait_make_dict
  4 
  5 
  6 class PubSubCommandsMixin:
  7     """Pub/Sub commands mixin.
  8 
  9     For commands details see: http://redis.io/commands/#pubsub
  10     """
  11 
  12     def publish(self, channel, message):
  13         """Post a message to channel."""
  14         return self.execute(b'PUBLISH', channel, message)
  15 
  16     def publish_json(self, channel, obj):
  17         """Post a JSON-encoded message to channel."""
  18         return self.publish(channel, json.dumps(obj))
  19 
  20     def subscribe(self, channel, *channels):
  21         """Switch connection to Pub/Sub mode and
  22         subscribe to specified channels.
  23 
  24         Arguments can be instances of :class:`~aioredis.Channel`.
  25 
  26         Returns :func:`asyncio.gather()` coroutine which when done will return
  27         a list of :class:`~aioredis.Channel` objects.
  28         """
  29         conn = self._pool_or_conn
  30         return wait_return_channels(
  31             conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),
  32             conn.pubsub_channels)
  33 
  34     def unsubscribe(self, channel, *channels):
  35         """Unsubscribe from specific channels.
  36 
  37         Arguments can be instances of :class:`~aioredis.Channel`.
  38         """
  39         conn = self._pool_or_conn
  40         return conn.execute_pubsub(b'UNSUBSCRIBE', channel, *channels)
  41 
  42     def psubscribe(self, pattern, *patterns):
  43         """Switch connection to Pub/Sub mode and
  44         subscribe to specified patterns.
  45 
  46         Arguments can be instances of :class:`~aioredis.Channel`.
  47 
  48         Returns :func:`asyncio.gather()` coroutine which when done will return
  49         a list of subscribed :class:`~aioredis.Channel` objects with
  50         ``is_pattern`` property set to ``True``.
  51         """
  52         conn = self._pool_or_conn
  53         return wait_return_channels(
  54             conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),
  55             conn.pubsub_patterns)
  56 
  57     def punsubscribe(self, pattern, *patterns):
  58         """Unsubscribe from specific patterns.
  59 
  60         Arguments can be instances of :class:`~aioredis.Channel`.
  61         """
  62         conn = self._pool_or_conn
  63         return conn.execute_pubsub(b'PUNSUBSCRIBE', pattern, *patterns)
  64 
  65     def pubsub_channels(self, pattern=None):
  66         """Lists the currently active channels."""
  67         args = [b'PUBSUB', b'CHANNELS']
  68         if pattern is not None:
  69             args.append(pattern)
  70         return self.execute(*args)
  71 
  72     def pubsub_numsub(self, *channels):
  73         """Returns the number of subscribers for the specified channels."""
  74         return wait_make_dict(self.execute(
  75             b'PUBSUB', b'NUMSUB', *channels))
  76 
  77     def pubsub_numpat(self):
  78         """Returns the number of subscriptions to patterns."""
  79         return self.execute(b'PUBSUB', b'NUMPAT')
  80 
  81     @property
  82     def channels(self):
  83         """Returns read-only channels dict.
  84 
  85         See :attr:`~aioredis.RedisConnection.pubsub_channels`
  86         """
  87         return self._pool_or_conn.pubsub_channels
  88 
  89     @property
  90     def patterns(self):
  91         """Returns read-only patterns dict.
  92 
  93         See :attr:`~aioredis.RedisConnection.pubsub_patterns`
  94         """
  95         return self._pool_or_conn.pubsub_patterns
  96 
  97     @property
  98     def in_pubsub(self):
  99         """Indicates that connection is in PUB/SUB mode.
  100 
  101         Provides the number of subscribed channels.
  102         """
  103         return self._pool_or_conn.in_pubsub
  104 
  105 
  106 async def wait_return_channels(fut, channels_dict):
  107     return [channels_dict[name]
  108             for cmd, name, count in await fut]
  109
  [end of aioredis/commands/pubsub.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/aioredis/commands/pubsub.py b/aioredis/commands/pubsub.py
  --- a/aioredis/commands/pubsub.py
  +++ b/aioredis/commands/pubsub.py
  @@ -29,7 +29,7 @@
           conn = self._pool_or_conn
           return wait_return_channels(
               conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),
  -            conn.pubsub_channels)
  +            conn, 'pubsub_channels')
   
       def unsubscribe(self, channel, *channels):
           """Unsubscribe from specific channels.
  @@ -52,7 +52,7 @@
           conn = self._pool_or_conn
           return wait_return_channels(
               conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),
  -            conn.pubsub_patterns)
  +            conn, 'pubsub_patterns')
   
       def punsubscribe(self, pattern, *patterns):
           """Unsubscribe from specific patterns.
  @@ -103,6 +103,7 @@
           return self._pool_or_conn.in_pubsub
   
   
  -async def wait_return_channels(fut, channels_dict):
  -    return [channels_dict[name]
  -            for cmd, name, count in await fut]
  +async def wait_return_channels(fut, conn, field):
  +    res = await fut
  +    channels_dict = getattr(conn, field)
  +    return [channels_dict[name] for cmd, name, count in res]
  
verification_info: {"golden_diff": "diff --git a/aioredis/commands/pubsub.py b/aioredis/commands/pubsub.py\n--- a/aioredis/commands/pubsub.py\n+++ b/aioredis/commands/pubsub.py\n@@ -29,7 +29,7 @@\n         conn = self._pool_or_conn\n         return wait_return_channels(\n             conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),\n-            conn.pubsub_channels)\n+            conn, 'pubsub_channels')\n \n     def unsubscribe(self, channel, *channels):\n         \"\"\"Unsubscribe from specific channels.\n@@ -52,7 +52,7 @@\n         conn = self._pool_or_conn\n         return wait_return_channels(\n             conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),\n-            conn.pubsub_patterns)\n+            conn, 'pubsub_patterns')\n \n     def punsubscribe(self, pattern, *patterns):\n         \"\"\"Unsubscribe from specific patterns.\n@@ -103,6 +103,7 @@\n         return self._pool_or_conn.in_pubsub\n \n \n-async def wait_return_channels(fut, channels_dict):\n-    return [channels_dict[name]\n-            for cmd, name, count in await fut]\n+async def wait_return_channels(fut, conn, field):\n+    res = await fut\n+    channels_dict = getattr(conn, field)\n+    return [channels_dict[name] for cmd, name, count in res]\n", "issue": "Fixed ConnectionsPool.[pubsub_channels/pubsub_patterns]\nFixed bug in `commands.pubsub.PubSubCommandsMixin.subscribe` (and psubscribe). `ConnectionsPool.pubsub_channles` code was called before `ConnectionsPool._pubsub_conn` creation, and therefore `pubsub_channles` \n", "before_files": [{"content": "import json\n\nfrom aioredis.util import wait_make_dict\n\n\nclass PubSubCommandsMixin:\n    \"\"\"Pub/Sub commands mixin.\n\n    For commands details see: http://redis.io/commands/#pubsub\n    \"\"\"\n\n    def publish(self, channel, message):\n        \"\"\"Post a message to channel.\"\"\"\n        return self.execute(b'PUBLISH', channel, message)\n\n    def publish_json(self, channel, obj):\n        \"\"\"Post a JSON-encoded message to channel.\"\"\"\n        return self.publish(channel, json.dumps(obj))\n\n    def subscribe(self, channel, *channels):\n        \"\"\"Switch connection to Pub/Sub mode and\n        subscribe to specified channels.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n\n        Returns :func:`asyncio.gather()` coroutine which when done will return\n        a list of :class:`~aioredis.Channel` objects.\n        \"\"\"\n        conn = self._pool_or_conn\n        return wait_return_channels(\n            conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),\n            conn.pubsub_channels)\n\n    def unsubscribe(self, channel, *channels):\n        \"\"\"Unsubscribe from specific channels.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n        \"\"\"\n        conn = self._pool_or_conn\n        return conn.execute_pubsub(b'UNSUBSCRIBE', channel, *channels)\n\n    def psubscribe(self, pattern, *patterns):\n        \"\"\"Switch connection to Pub/Sub mode and\n        subscribe to specified patterns.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n\n        Returns :func:`asyncio.gather()` coroutine which when done will return\n        a list of subscribed :class:`~aioredis.Channel` objects with\n        ``is_pattern`` property set to ``True``.\n        \"\"\"\n        conn = self._pool_or_conn\n        return wait_return_channels(\n            conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),\n            conn.pubsub_patterns)\n\n    def punsubscribe(self, pattern, *patterns):\n        \"\"\"Unsubscribe from specific patterns.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n        \"\"\"\n        conn = self._pool_or_conn\n        return conn.execute_pubsub(b'PUNSUBSCRIBE', pattern, *patterns)\n\n    def pubsub_channels(self, pattern=None):\n        \"\"\"Lists the currently active channels.\"\"\"\n        args = [b'PUBSUB', b'CHANNELS']\n        if pattern is not None:\n            args.append(pattern)\n        return self.execute(*args)\n\n    def pubsub_numsub(self, *channels):\n        \"\"\"Returns the number of subscribers for the specified channels.\"\"\"\n        return wait_make_dict(self.execute(\n            b'PUBSUB', b'NUMSUB', *channels))\n\n    def pubsub_numpat(self):\n        \"\"\"Returns the number of subscriptions to patterns.\"\"\"\n        return self.execute(b'PUBSUB', b'NUMPAT')\n\n    @property\n    def channels(self):\n        \"\"\"Returns read-only channels dict.\n\n        See :attr:`~aioredis.RedisConnection.pubsub_channels`\n        \"\"\"\n        return self._pool_or_conn.pubsub_channels\n\n    @property\n    def patterns(self):\n        \"\"\"Returns read-only patterns dict.\n\n        See :attr:`~aioredis.RedisConnection.pubsub_patterns`\n        \"\"\"\n        return self._pool_or_conn.pubsub_patterns\n\n    @property\n    def in_pubsub(self):\n        \"\"\"Indicates that connection is in PUB/SUB mode.\n\n        Provides the number of subscribed channels.\n        \"\"\"\n        return self._pool_or_conn.in_pubsub\n\n\nasync def wait_return_channels(fut, channels_dict):\n    return [channels_dict[name]\n            for cmd, name, count in await fut]\n", "path": "aioredis/commands/pubsub.py"}]}