Skip to content

Commit 8088642

Browse files
daveisferavladvildanov
authored andcommitted
Run pyupgrade for 3.8 (#3236)
Run pyupgrade for 3.8.
1 parent ff944e1 commit 8088642

File tree

12 files changed

+31
-43
lines changed

12 files changed

+31
-43
lines changed

redis/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sys
1+
from importlib import metadata
22

33
from redis import asyncio # noqa
44
from redis.backoff import default_backoff
@@ -36,11 +36,6 @@
3636
)
3737
from redis.utils import from_url
3838

39-
if sys.version_info >= (3, 8):
40-
from importlib import metadata
41-
else:
42-
import importlib_metadata as metadata
43-
4439

4540
def int_or_str(value):
4641
try:

redis/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def clean_health_check_responses(self) -> None:
828828
else:
829829
raise PubSubError(
830830
"A non health check response was cleaned by "
831-
"execute_command: {0}".format(response)
831+
"execute_command: {}".format(response)
832832
)
833833
ttl -= 1
834834

redis/cluster.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,8 +1851,7 @@ def _sharded_message_generator(self):
18511851

18521852
def _pubsubs_generator(self):
18531853
while True:
1854-
for pubsub in self.node_pubsub_mapping.values():
1855-
yield pubsub
1854+
yield from self.node_pubsub_mapping.values()
18561855

18571856
def get_sharded_message(
18581857
self, ignore_subscribe_messages=False, timeout=0.0, target_node=None

redis/commands/bf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .info import BFInfo, CFInfo, CMSInfo, TDigestInfo, TopKInfo
66

77

8-
class AbstractBloom(object):
8+
class AbstractBloom:
99
"""
1010
The client allows to interact with RedisBloom and use all of
1111
it's functionality.

redis/commands/bf/info.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ..helpers import nativestr
22

33

4-
class BFInfo(object):
4+
class BFInfo:
55
capacity = None
66
size = None
77
filterNum = None
@@ -26,7 +26,7 @@ def __getitem__(self, item):
2626
return getattr(self, item)
2727

2828

29-
class CFInfo(object):
29+
class CFInfo:
3030
size = None
3131
bucketNum = None
3232
filterNum = None
@@ -57,7 +57,7 @@ def __getitem__(self, item):
5757
return getattr(self, item)
5858

5959

60-
class CMSInfo(object):
60+
class CMSInfo:
6161
width = None
6262
depth = None
6363
count = None
@@ -72,7 +72,7 @@ def __getitem__(self, item):
7272
return getattr(self, item)
7373

7474

75-
class TopKInfo(object):
75+
class TopKInfo:
7676
k = None
7777
width = None
7878
depth = None
@@ -89,7 +89,7 @@ def __getitem__(self, item):
8989
return getattr(self, item)
9090

9191

92-
class TDigestInfo(object):
92+
class TDigestInfo:
9393
compression = None
9494
capacity = None
9595
merged_nodes = None

redis/commands/graph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async def call_procedure(self, procedure, *args, read_only=False, **kwagrs):
252252
return await self.query(q, read_only=read_only)
253253

254254
async def labels(self):
255-
return ((await self.call_procedure(DB_LABELS, read_only=True))).result_set
255+
return (await self.call_procedure(DB_LABELS, read_only=True)).result_set
256256

257257
async def property_keys(self):
258258
return (await self.call_procedure(DB_PROPERTYKEYS, read_only=True)).result_set

redis/commands/json/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def set_file(
314314
315315
"""
316316

317-
with open(file_name, "r") as fp:
317+
with open(file_name) as fp:
318318
file_content = loads(fp.read())
319319

320320
return self.set(name, path, file_content, nx=nx, xx=xx, decode_keys=decode_keys)

redis/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import sys
32
from contextlib import contextmanager
43
from functools import wraps
54
from typing import Any, Dict, Mapping, Union
@@ -28,10 +27,7 @@
2827
except ImportError:
2928
CRYPTOGRAPHY_AVAILABLE = False
3029

31-
if sys.version_info >= (3, 8):
32-
from importlib import metadata
33-
else:
34-
import importlib_metadata as metadata
30+
from importlib import metadata
3531

3632

3733
def from_url(url, **kwargs):

tests/ssl_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ def get_ssl_filename(name):
99
os.path.join(root, "..", "dockers", "stunnel", "keys")
1010
)
1111
if not os.path.isdir(cert_dir):
12-
raise IOError(f"No SSL certificates found. They should be in {cert_dir}")
12+
raise OSError(f"No SSL certificates found. They should be in {cert_dir}")
1313

1414
return os.path.join(cert_dir, name)

tests/test_asyncio/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
try:
55
mock.AsyncMock
66
except AttributeError:
7-
import mock
7+
from unittest import mock
88

99
try:
1010
from contextlib import aclosing

tests/test_asyncio/test_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,14 +1487,14 @@ async def test_withsuffixtrie(decoded_r: redis.Redis):
14871487
assert await decoded_r.ft().dropindex("idx")
14881488

14891489
# create withsuffixtrie index (text field)
1490-
assert await decoded_r.ft().create_index((TextField("t", withsuffixtrie=True)))
1490+
assert await decoded_r.ft().create_index(TextField("t", withsuffixtrie=True))
14911491
await waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx"))
14921492
info = await decoded_r.ft().info()
14931493
assert "WITHSUFFIXTRIE" in info["attributes"][0]
14941494
assert await decoded_r.ft().dropindex("idx")
14951495

14961496
# create withsuffixtrie index (tag field)
1497-
assert await decoded_r.ft().create_index((TagField("t", withsuffixtrie=True)))
1497+
assert await decoded_r.ft().create_index(TagField("t", withsuffixtrie=True))
14981498
await waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx"))
14991499
info = await decoded_r.ft().info()
15001500
assert "WITHSUFFIXTRIE" in info["attributes"][0]
@@ -1504,14 +1504,14 @@ async def test_withsuffixtrie(decoded_r: redis.Redis):
15041504
assert await decoded_r.ft().dropindex("idx")
15051505

15061506
# create withsuffixtrie index (text fields)
1507-
assert await decoded_r.ft().create_index((TextField("t", withsuffixtrie=True)))
1507+
assert await decoded_r.ft().create_index(TextField("t", withsuffixtrie=True))
15081508
waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx"))
15091509
info = await decoded_r.ft().info()
15101510
assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"]
15111511
assert await decoded_r.ft().dropindex("idx")
15121512

15131513
# create withsuffixtrie index (tag field)
1514-
assert await decoded_r.ft().create_index((TagField("t", withsuffixtrie=True)))
1514+
assert await decoded_r.ft().create_index(TagField("t", withsuffixtrie=True))
15151515
waitForIndex(decoded_r, getattr(decoded_r.ft(), "index_name", "idx"))
15161516
info = await decoded_r.ft().info()
15171517
assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"]

tests/test_search.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,16 +1383,14 @@ def test_aggregations_apply(client):
13831383
)
13841384
res = client.ft().aggregate(req)
13851385
if is_resp2_connection(client):
1386-
res_set = set([res.rows[0][1], res.rows[1][1]])
1387-
assert res_set == set(["6373878785249699840", "6373878758592700416"])
1386+
res_set = {res.rows[0][1], res.rows[1][1]}
1387+
assert res_set == {"6373878785249699840", "6373878758592700416"}
13881388
else:
1389-
res_set = set(
1390-
[
1391-
res["results"][0]["extra_attributes"]["CreatedDateTimeUTC"],
1392-
res["results"][1]["extra_attributes"]["CreatedDateTimeUTC"],
1393-
],
1394-
)
1395-
assert res_set == set(["6373878785249699840", "6373878758592700416"])
1389+
res_set = {
1390+
res["results"][0]["extra_attributes"]["CreatedDateTimeUTC"],
1391+
res["results"][1]["extra_attributes"]["CreatedDateTimeUTC"],
1392+
}
1393+
assert res_set == {"6373878785249699840", "6373878758592700416"}
13961394

13971395

13981396
@pytest.mark.redismod
@@ -2099,7 +2097,7 @@ def test_numeric_params(client):
20992097
@pytest.mark.redismod
21002098
@skip_ifmodversion_lt("2.4.3", "search")
21012099
def test_geo_params(client):
2102-
client.ft().create_index((GeoField("g")))
2100+
client.ft().create_index(GeoField("g"))
21032101
client.hset("doc1", mapping={"g": "29.69465, 34.95126"})
21042102
client.hset("doc2", mapping={"g": "29.69350, 34.94737"})
21052103
client.hset("doc3", mapping={"g": "29.68746, 34.94882"})
@@ -2228,14 +2226,14 @@ def test_withsuffixtrie(client: redis.Redis):
22282226
assert client.ft().dropindex("idx")
22292227

22302228
# create withsuffixtrie index (text fields)
2231-
assert client.ft().create_index((TextField("t", withsuffixtrie=True)))
2229+
assert client.ft().create_index(TextField("t", withsuffixtrie=True))
22322230
waitForIndex(client, getattr(client.ft(), "index_name", "idx"))
22332231
info = client.ft().info()
22342232
assert "WITHSUFFIXTRIE" in info["attributes"][0]
22352233
assert client.ft().dropindex("idx")
22362234

22372235
# create withsuffixtrie index (tag field)
2238-
assert client.ft().create_index((TagField("t", withsuffixtrie=True)))
2236+
assert client.ft().create_index(TagField("t", withsuffixtrie=True))
22392237
waitForIndex(client, getattr(client.ft(), "index_name", "idx"))
22402238
info = client.ft().info()
22412239
assert "WITHSUFFIXTRIE" in info["attributes"][0]
@@ -2245,14 +2243,14 @@ def test_withsuffixtrie(client: redis.Redis):
22452243
assert client.ft().dropindex("idx")
22462244

22472245
# create withsuffixtrie index (text fields)
2248-
assert client.ft().create_index((TextField("t", withsuffixtrie=True)))
2246+
assert client.ft().create_index(TextField("t", withsuffixtrie=True))
22492247
waitForIndex(client, getattr(client.ft(), "index_name", "idx"))
22502248
info = client.ft().info()
22512249
assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"]
22522250
assert client.ft().dropindex("idx")
22532251

22542252
# create withsuffixtrie index (tag field)
2255-
assert client.ft().create_index((TagField("t", withsuffixtrie=True)))
2253+
assert client.ft().create_index(TagField("t", withsuffixtrie=True))
22562254
waitForIndex(client, getattr(client.ft(), "index_name", "idx"))
22572255
info = client.ft().info()
22582256
assert "WITHSUFFIXTRIE" in info["attributes"][0]["flags"]
@@ -2271,7 +2269,7 @@ def test_query_timeout(r: redis.Redis):
22712269

22722270
@pytest.mark.redismod
22732271
def test_geoshape(client: redis.Redis):
2274-
client.ft().create_index((GeoShapeField("geom", GeoShapeField.FLAT)))
2272+
client.ft().create_index(GeoShapeField("geom", GeoShapeField.FLAT))
22752273
waitForIndex(client, getattr(client.ft(), "index_name", "idx"))
22762274
client.hset("small", "geom", "POLYGON((1 1, 1 100, 100 100, 100 1, 1 1))")
22772275
client.hset("large", "geom", "POLYGON((1 1, 1 200, 200 200, 200 1, 1 1))")

0 commit comments

Comments
 (0)