Skip to content

Commit 97095cc

Browse files
gerzsevladvildanov
authored andcommitted
Upgrade Flake8 (#3323)
Use the latest available Flake8. Fix some linter errors that surfaced. Take the opportunity to fix typing hints and remove code duplication around CommandsProtocol.
1 parent d5868cc commit 97095cc

File tree

9 files changed

+22
-36
lines changed

9 files changed

+22
-36
lines changed

dev_requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
black==24.3.0
22
cachetools
33
click==8.0.4
4-
flake8-isort==6.0.0
5-
flake8==5.0.4
4+
flake8-isort
5+
flake8
66
flynt~=0.69.0
77
invoke==2.2.0
88
mock

redis/_parsers/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def parse_geosearch_generic(response, **options):
507507
except KeyError: # it means the command was sent via execute_command
508508
return response
509509

510-
if type(response) != list:
510+
if not isinstance(response, list):
511511
response_list = [response]
512512
else:
513513
response_list = response

redis/commands/core.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,6 @@ def failover(self):
13801380
)
13811381

13821382

1383-
AsyncManagementCommands = ManagementCommands
1384-
1385-
13861383
class AsyncManagementCommands(ManagementCommands):
13871384
async def command_info(self, **kwargs) -> None:
13881385
return super().command_info(**kwargs)

redis/commands/timeseries/info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, args):
7878
self.chunk_size = response["chunkSize"]
7979
if "duplicatePolicy" in response:
8080
self.duplicate_policy = response["duplicatePolicy"]
81-
if type(self.duplicate_policy) == bytes:
81+
if isinstance(self.duplicate_policy, bytes):
8282
self.duplicate_policy = self.duplicate_policy.decode()
8383

8484
def get(self, item):

redis/typing.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@
5555
class CommandsProtocol(Protocol):
5656
connection_pool: Union["AsyncConnectionPool", "ConnectionPool"]
5757

58-
def execute_command(self, *args, **options): ...
58+
def execute_command(self, *args, **options) -> ResponseT: ...
5959

6060

61-
class ClusterCommandsProtocol(CommandsProtocol, Protocol):
61+
class ClusterCommandsProtocol(CommandsProtocol):
6262
encoder: "Encoder"
63-
64-
def execute_command(self, *args, **options) -> Union[Any, Awaitable]: ...

tests/test_asyncio/test_connection_pool.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,17 @@ async def test_repr_contains_db_info_tcp(self):
180180
async with self.get_pool(
181181
connection_kwargs=connection_kwargs, connection_class=redis.Connection
182182
) as pool:
183-
expected = (
184-
"ConnectionPool<Connection<"
185-
"host=localhost,port=6379,db=1,client_name=test-client>>"
186-
)
187-
assert repr(pool) == expected
183+
expected = "host=localhost,port=6379,db=1,client_name=test-client"
184+
assert expected in repr(pool)
188185

189186
async def test_repr_contains_db_info_unix(self):
190187
connection_kwargs = {"path": "/abc", "db": 1, "client_name": "test-client"}
191188
async with self.get_pool(
192189
connection_kwargs=connection_kwargs,
193190
connection_class=redis.UnixDomainSocketConnection,
194191
) as pool:
195-
expected = (
196-
"ConnectionPool<UnixDomainSocketConnection<"
197-
"path=/abc,db=1,client_name=test-client>>"
198-
)
199-
assert repr(pool) == expected
192+
expected = "path=/abc,db=1,client_name=test-client"
193+
assert expected in repr(pool)
200194

201195

202196
class TestBlockingConnectionPool:
@@ -293,23 +287,17 @@ def test_repr_contains_db_info_tcp(self):
293287
pool = redis.ConnectionPool(
294288
host="localhost", port=6379, client_name="test-client"
295289
)
296-
expected = (
297-
"ConnectionPool<Connection<"
298-
"host=localhost,port=6379,db=0,client_name=test-client>>"
299-
)
300-
assert repr(pool) == expected
290+
expected = "host=localhost,port=6379,db=0,client_name=test-client"
291+
assert expected in repr(pool)
301292

302293
def test_repr_contains_db_info_unix(self):
303294
pool = redis.ConnectionPool(
304295
connection_class=redis.UnixDomainSocketConnection,
305296
path="abc",
306297
client_name="test-client",
307298
)
308-
expected = (
309-
"ConnectionPool<UnixDomainSocketConnection<"
310-
"path=abc,db=0,client_name=test-client>>"
311-
)
312-
assert repr(pool) == expected
299+
expected = "path=abc,db=0,client_name=test-client"
300+
assert expected in repr(pool)
313301

314302

315303
class TestConnectionPoolURLParsing:
@@ -659,7 +647,9 @@ def test_connect_from_url_tcp(self):
659647
connection = redis.Redis.from_url("redis://localhost")
660648
pool = connection.connection_pool
661649

662-
assert re.match("(.*)<(.*)<(.*)>>", repr(pool)).groups() == (
650+
assert re.match(
651+
r"< .*?([^\.]+) \( < .*?([^\.]+) \( (.+) \) > \) >", repr(pool), re.VERBOSE
652+
).groups() == (
663653
"ConnectionPool",
664654
"Connection",
665655
"host=localhost,port=6379,db=0",
@@ -669,7 +659,9 @@ def test_connect_from_url_unix(self):
669659
connection = redis.Redis.from_url("unix:///path/to/socket")
670660
pool = connection.connection_pool
671661

672-
assert re.match("(.*)<(.*)<(.*)>>", repr(pool)).groups() == (
662+
assert re.match(
663+
r"< .*?([^\.]+) \( < .*?([^\.]+) \( (.+) \) > \) >", repr(pool), re.VERBOSE
664+
).groups() == (
673665
"ConnectionPool",
674666
"UnixDomainSocketConnection",
675667
"path=/path/to/socket,db=0",

tests/test_asyncio/test_lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,4 @@ def __init__(self, *args, **kwargs):
237237
pass
238238

239239
lock = r.lock("foo", lock_class=MyLock)
240-
assert type(lock) == MyLock
240+
assert isinstance(lock, MyLock)

tests/test_json.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ def test_json_forget_with_dollar(client):
446446
client.json().forget("not_a_document", "..a")
447447

448448

449-
@pytest.mark.onlynoncluster
450449
@pytest.mark.redismod
451450
def test_json_mget_dollar(client):
452451
# Test mget with multi paths

tests/test_lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,4 @@ def __init__(self, *args, **kwargs):
257257
pass
258258

259259
lock = r.lock("foo", lock_class=MyLock)
260-
assert type(lock) == MyLock
260+
assert isinstance(lock, MyLock)

0 commit comments

Comments
 (0)