diff --git a/redis/__init__.py b/redis/__init__.py index 495d2d99bb..94324a0de8 100644 --- a/redis/__init__.py +++ b/redis/__init__.py @@ -1,4 +1,4 @@ -import sys +from importlib import metadata from redis import asyncio # noqa from redis.backoff import default_backoff @@ -36,11 +36,6 @@ ) from redis.utils import from_url -if sys.version_info >= (3, 8): - from importlib import metadata -else: - import importlib_metadata as metadata - def int_or_str(value): try: diff --git a/redis/client.py b/redis/client.py index 02fc724322..b7a1f88d92 100755 --- a/redis/client.py +++ b/redis/client.py @@ -831,7 +831,7 @@ def clean_health_check_responses(self) -> None: else: raise PubSubError( "A non health check response was cleaned by " - "execute_command: {0}".format(response) + "execute_command: {}".format(response) ) ttl -= 1 diff --git a/redis/cluster.py b/redis/cluster.py index e792d51867..73bc0b8b8a 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -1851,8 +1851,7 @@ def _sharded_message_generator(self): def _pubsubs_generator(self): while True: - for pubsub in self.node_pubsub_mapping.values(): - yield pubsub + yield from self.node_pubsub_mapping.values() def get_sharded_message( self, ignore_subscribe_messages=False, timeout=0.0, target_node=None diff --git a/redis/commands/bf/__init__.py b/redis/commands/bf/__init__.py index 959358f8e8..29c5c18767 100644 --- a/redis/commands/bf/__init__.py +++ b/redis/commands/bf/__init__.py @@ -5,7 +5,7 @@ from .info import BFInfo, CFInfo, CMSInfo, TDigestInfo, TopKInfo -class AbstractBloom(object): +class AbstractBloom: """ The client allows to interact with RedisBloom and use all of it's functionality. diff --git a/redis/commands/bf/info.py b/redis/commands/bf/info.py index e1f0208609..1a876c1655 100644 --- a/redis/commands/bf/info.py +++ b/redis/commands/bf/info.py @@ -1,7 +1,7 @@ from ..helpers import nativestr -class BFInfo(object): +class BFInfo: capacity = None size = None filterNum = None @@ -26,7 +26,7 @@ def __getitem__(self, item): return getattr(self, item) -class CFInfo(object): +class CFInfo: size = None bucketNum = None filterNum = None @@ -57,7 +57,7 @@ def __getitem__(self, item): return getattr(self, item) -class CMSInfo(object): +class CMSInfo: width = None depth = None count = None @@ -72,7 +72,7 @@ def __getitem__(self, item): return getattr(self, item) -class TopKInfo(object): +class TopKInfo: k = None width = None depth = None @@ -89,7 +89,7 @@ def __getitem__(self, item): return getattr(self, item) -class TDigestInfo(object): +class TDigestInfo: compression = None capacity = None merged_nodes = None diff --git a/redis/commands/graph/__init__.py b/redis/commands/graph/__init__.py index ffaf1fb4ff..ddc0e34f4c 100644 --- a/redis/commands/graph/__init__.py +++ b/redis/commands/graph/__init__.py @@ -252,7 +252,7 @@ async def call_procedure(self, procedure, *args, read_only=False, **kwagrs): return await self.query(q, read_only=read_only) async def labels(self): - return ((await self.call_procedure(DB_LABELS, read_only=True))).result_set + return (await self.call_procedure(DB_LABELS, read_only=True)).result_set async def property_keys(self): return (await self.call_procedure(DB_PROPERTYKEYS, read_only=True)).result_set diff --git a/redis/commands/json/commands.py b/redis/commands/json/commands.py index b37dc37687..da879df611 100644 --- a/redis/commands/json/commands.py +++ b/redis/commands/json/commands.py @@ -314,7 +314,7 @@ def set_file( """ - with open(file_name, "r") as fp: + with open(file_name) as fp: file_content = loads(fp.read()) return self.set(name, path, file_content, nx=nx, xx=xx, decode_keys=decode_keys) diff --git a/redis/utils.py b/redis/utils.py index 01fdfed7a2..ea2eac149e 100644 --- a/redis/utils.py +++ b/redis/utils.py @@ -1,5 +1,4 @@ import logging -import sys from contextlib import contextmanager from functools import wraps from typing import Any, Dict, Mapping, Union @@ -28,10 +27,7 @@ except ImportError: CRYPTOGRAPHY_AVAILABLE = False -if sys.version_info >= (3, 8): - from importlib import metadata -else: - import importlib_metadata as metadata +from importlib import metadata def from_url(url, **kwargs): diff --git a/tests/ssl_utils.py b/tests/ssl_utils.py index ab9c2e8944..1de53bbf66 100644 --- a/tests/ssl_utils.py +++ b/tests/ssl_utils.py @@ -9,6 +9,6 @@ def get_ssl_filename(name): os.path.join(root, "..", "dockers", "stunnel", "keys") ) if not os.path.isdir(cert_dir): - raise IOError(f"No SSL certificates found. They should be in {cert_dir}") + raise OSError(f"No SSL certificates found. They should be in {cert_dir}") return os.path.join(cert_dir, name) diff --git a/tests/test_asyncio/compat.py b/tests/test_asyncio/compat.py index 4a9778b70a..aa1dc49af0 100644 --- a/tests/test_asyncio/compat.py +++ b/tests/test_asyncio/compat.py @@ -4,7 +4,7 @@ try: mock.AsyncMock except AttributeError: - import mock + from unittest import mock try: from contextlib import aclosing diff --git a/tests/test_asyncio/test_search.py b/tests/test_asyncio/test_search.py index 1f1931e28a..8d42d08b66 100644 --- a/tests/test_asyncio/test_search.py +++ b/tests/test_asyncio/test_search.py @@ -1487,14 +1487,14 @@ async def test_withsuffixtrie(decoded_r: redis.Redis): assert await decoded_r.ft().dropindex("idx") # create withsuffixtrie index (text field) - assert await decoded_r.ft().create_index((TextField("t", withsuffixtrie=True))) + assert await decoded_r.ft().create_index(TextField("t", withsuffixtrie=True)) await waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx")) info = await decoded_r.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0] assert await decoded_r.ft().dropindex("idx") # create withsuffixtrie index (tag field) - assert await decoded_r.ft().create_index((TagField("t", withsuffixtrie=True))) + assert await decoded_r.ft().create_index(TagField("t", withsuffixtrie=True)) await waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx")) info = await decoded_r.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0] @@ -1504,14 +1504,14 @@ async def test_withsuffixtrie(decoded_r: redis.Redis): assert await decoded_r.ft().dropindex("idx") # create withsuffixtrie index (text fields) - assert await decoded_r.ft().create_index((TextField("t", withsuffixtrie=True))) + assert await decoded_r.ft().create_index(TextField("t", withsuffixtrie=True)) waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx")) info = await decoded_r.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"] assert await decoded_r.ft().dropindex("idx") # create withsuffixtrie index (tag field) - assert await decoded_r.ft().create_index((TagField("t", withsuffixtrie=True))) + assert await decoded_r.ft().create_index(TagField("t", withsuffixtrie=True)) waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx")) info = await decoded_r.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"] diff --git a/tests/test_search.py b/tests/test_search.py index bfe204254c..f19c193891 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1383,16 +1383,14 @@ def test_aggregations_apply(client): ) res = client.ft().aggregate(req) if is_resp2_connection(client): - res_set = set([res.rows[0][1], res.rows[1][1]]) - assert res_set == set(["6373878785249699840", "6373878758592700416"]) + res_set = {res.rows[0][1], res.rows[1][1]} + assert res_set == {"6373878785249699840", "6373878758592700416"} else: - res_set = set( - [ - res["results"][0]["extra_attributes"]["CreatedDateTimeUTC"], - res["results"][1]["extra_attributes"]["CreatedDateTimeUTC"], - ], - ) - assert res_set == set(["6373878785249699840", "6373878758592700416"]) + res_set = { + res["results"][0]["extra_attributes"]["CreatedDateTimeUTC"], + res["results"][1]["extra_attributes"]["CreatedDateTimeUTC"], + } + assert res_set == {"6373878785249699840", "6373878758592700416"} @pytest.mark.redismod @@ -2099,7 +2097,7 @@ def test_numeric_params(client): @pytest.mark.redismod @skip_ifmodversion_lt("2.4.3", "search") def test_geo_params(client): - client.ft().create_index((GeoField("g"))) + client.ft().create_index(GeoField("g")) client.hset("doc1", mapping={"g": "29.69465, 34.95126"}) client.hset("doc2", mapping={"g": "29.69350, 34.94737"}) client.hset("doc3", mapping={"g": "29.68746, 34.94882"}) @@ -2228,14 +2226,14 @@ def test_withsuffixtrie(client: redis.Redis): assert client.ft().dropindex("idx") # create withsuffixtrie index (text fields) - assert client.ft().create_index((TextField("t", withsuffixtrie=True))) + assert client.ft().create_index(TextField("t", withsuffixtrie=True)) waitForIndex(client, getattr(client.ft(), "index_name", "idx")) info = client.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0] assert client.ft().dropindex("idx") # create withsuffixtrie index (tag field) - assert client.ft().create_index((TagField("t", withsuffixtrie=True))) + assert client.ft().create_index(TagField("t", withsuffixtrie=True)) waitForIndex(client, getattr(client.ft(), "index_name", "idx")) info = client.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0] @@ -2245,14 +2243,14 @@ def test_withsuffixtrie(client: redis.Redis): assert client.ft().dropindex("idx") # create withsuffixtrie index (text fields) - assert client.ft().create_index((TextField("t", withsuffixtrie=True))) + assert client.ft().create_index(TextField("t", withsuffixtrie=True)) waitForIndex(client, getattr(client.ft(), "index_name", "idx")) info = client.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"] assert client.ft().dropindex("idx") # create withsuffixtrie index (tag field) - assert client.ft().create_index((TagField("t", withsuffixtrie=True))) + assert client.ft().create_index(TagField("t", withsuffixtrie=True)) waitForIndex(client, getattr(client.ft(), "index_name", "idx")) info = client.ft().info() assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"] @@ -2271,7 +2269,7 @@ def test_query_timeout(r: redis.Redis): @pytest.mark.redismod def test_geoshape(client: redis.Redis): - client.ft().create_index((GeoShapeField("geom", GeoShapeField.FLAT))) + client.ft().create_index(GeoShapeField("geom", GeoShapeField.FLAT)) waitForIndex(client, getattr(client.ft(), "index_name", "idx")) client.hset("small", "geom", "POLYGON((1 1, 1 100, 100 100, 100 1, 1 1))") client.hset("large", "geom", "POLYGON((1 1, 1 200, 200 200, 200 1, 1 1))")