From 643eb0f57f5705949fda4419baf2d53c56717a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 3 Jan 2023 11:23:49 +0100 Subject: [PATCH] fix: prevent KeyError when popping an unknown property (#552) * fix: prevent KeyError when popping an unknown property * fix: typo in version range for mypy --- algoliasearch/iterators.py | 3 ++- algoliasearch/iterators_async.py | 3 ++- tox.ini | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/algoliasearch/iterators.py b/algoliasearch/iterators.py index f5f62c6a4..009cdae4f 100644 --- a/algoliasearch/iterators.py +++ b/algoliasearch/iterators.py @@ -56,7 +56,8 @@ def __next__(self): if len(self._raw_response["hits"]): hit = self._raw_response["hits"].pop(0) - hit.pop("_highlightResult") + if "_highlightResult" in hit: + hit.pop("_highlightResult") return hit diff --git a/algoliasearch/iterators_async.py b/algoliasearch/iterators_async.py index 3d0916840..0339d8d6e 100644 --- a/algoliasearch/iterators_async.py +++ b/algoliasearch/iterators_async.py @@ -37,7 +37,8 @@ def __anext__(self): # type: ignore if len(self._raw_response["hits"]): hit = self._raw_response["hits"].pop(0) - hit.pop("_highlightResult") + if "_highlightResult" in hit: + hit.pop("_highlightResult") return hit diff --git a/tox.ini b/tox.ini index 63dd1cccd..a19a107f1 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ typing = >=3.6,<4.0; python_version < '3.5' asyncio = >=3.4,<4.0 aiohttp = >=2.0,<4.0; python_version >= '3.4.2' async_timeout = >=2.0,<4.0 -mypy = >=0.6,<7.0 +mypy = >=0.600,<0.900 flake8 = ==3.8.3 black = ==22.3.0 twine = >=1.13,<2.0