From 8ae4f6de301d7ab80a2512ebc41ad4a7ac562b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Thu, 5 Oct 2023 14:20:00 +0000 Subject: [PATCH] Fix parsing resp3 dicts --- redis/_parsers/resp3.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/redis/_parsers/resp3.py b/redis/_parsers/resp3.py index ad766a8f95..569e7ee679 100644 --- a/redis/_parsers/resp3.py +++ b/redis/_parsers/resp3.py @@ -96,8 +96,9 @@ def _read_response(self, disable_decoding=False, push_request=False): pass # map response elif byte == b"%": - # we use this approach and not dict comprehension here - # because this dict comprehension fails in python 3.7 + # We cannot use a dict-comprehension to parse stream. + # Evaluation order of key:val expression in dict comprehension only + # became defined to be left-right in version 3.8 resp_dict = {} for _ in range(int(response)): key = self._read_response(disable_decoding=disable_decoding) @@ -225,12 +226,16 @@ async def _read_response( pass # map response elif byte == b"%": - response = { - (await self._read_response(disable_decoding=disable_decoding)): ( - await self._read_response(disable_decoding=disable_decoding) + # We cannot use a dict-comprehension to parse stream. + # Evaluation order of key:val expression in dict comprehension only + # became defined to be left-right in version 3.8 + resp_dict = {} + for _ in range(int(response)): + key = await self._read_response(disable_decoding=disable_decoding) + resp_dict[key] = await self._read_response( + disable_decoding=disable_decoding, push_request=push_request ) - for _ in range(int(response)) - } + response = resp_dict # push response elif byte == b">": response = [