Skip to content

Commit

Permalink
Upgrade Flake8 (#3323)
Browse files Browse the repository at this point in the history
Use the latest available Flake8. Fix some linter errors that surfaced.

Take the opportunity to fix typing hints and remove code duplication
around CommandsProtocol.
  • Loading branch information
gerzse authored and vladvildanov committed Sep 27, 2024
1 parent d5868cc commit 97095cc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 36 deletions.
4 changes: 2 additions & 2 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
black==24.3.0
cachetools
click==8.0.4
flake8-isort==6.0.0
flake8==5.0.4
flake8-isort
flake8
flynt~=0.69.0
invoke==2.2.0
mock
Expand Down
2 changes: 1 addition & 1 deletion redis/_parsers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def parse_geosearch_generic(response, **options):
except KeyError: # it means the command was sent via execute_command
return response

if type(response) != list:
if not isinstance(response, list):
response_list = [response]
else:
response_list = response
Expand Down
3 changes: 0 additions & 3 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,9 +1380,6 @@ def failover(self):
)


AsyncManagementCommands = ManagementCommands


class AsyncManagementCommands(ManagementCommands):
async def command_info(self, **kwargs) -> None:
return super().command_info(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion redis/commands/timeseries/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, args):
self.chunk_size = response["chunkSize"]
if "duplicatePolicy" in response:
self.duplicate_policy = response["duplicatePolicy"]
if type(self.duplicate_policy) == bytes:
if isinstance(self.duplicate_policy, bytes):
self.duplicate_policy = self.duplicate_policy.decode()

def get(self, item):
Expand Down
6 changes: 2 additions & 4 deletions redis/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@
class CommandsProtocol(Protocol):
connection_pool: Union["AsyncConnectionPool", "ConnectionPool"]

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


class ClusterCommandsProtocol(CommandsProtocol, Protocol):
class ClusterCommandsProtocol(CommandsProtocol):
encoder: "Encoder"

def execute_command(self, *args, **options) -> Union[Any, Awaitable]: ...
36 changes: 14 additions & 22 deletions tests/test_asyncio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,17 @@ async def test_repr_contains_db_info_tcp(self):
async with self.get_pool(
connection_kwargs=connection_kwargs, connection_class=redis.Connection
) as pool:
expected = (
"ConnectionPool<Connection<"
"host=localhost,port=6379,db=1,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "host=localhost,port=6379,db=1,client_name=test-client"
assert expected in repr(pool)

async def test_repr_contains_db_info_unix(self):
connection_kwargs = {"path": "/abc", "db": 1, "client_name": "test-client"}
async with self.get_pool(
connection_kwargs=connection_kwargs,
connection_class=redis.UnixDomainSocketConnection,
) as pool:
expected = (
"ConnectionPool<UnixDomainSocketConnection<"
"path=/abc,db=1,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "path=/abc,db=1,client_name=test-client"
assert expected in repr(pool)


class TestBlockingConnectionPool:
Expand Down Expand Up @@ -293,23 +287,17 @@ def test_repr_contains_db_info_tcp(self):
pool = redis.ConnectionPool(
host="localhost", port=6379, client_name="test-client"
)
expected = (
"ConnectionPool<Connection<"
"host=localhost,port=6379,db=0,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "host=localhost,port=6379,db=0,client_name=test-client"
assert expected in repr(pool)

def test_repr_contains_db_info_unix(self):
pool = redis.ConnectionPool(
connection_class=redis.UnixDomainSocketConnection,
path="abc",
client_name="test-client",
)
expected = (
"ConnectionPool<UnixDomainSocketConnection<"
"path=abc,db=0,client_name=test-client>>"
)
assert repr(pool) == expected
expected = "path=abc,db=0,client_name=test-client"
assert expected in repr(pool)


class TestConnectionPoolURLParsing:
Expand Down Expand Up @@ -659,7 +647,9 @@ def test_connect_from_url_tcp(self):
connection = redis.Redis.from_url("redis://localhost")
pool = connection.connection_pool

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

assert re.match("(.*)<(.*)<(.*)>>", repr(pool)).groups() == (
assert re.match(
r"< .*?([^\.]+) \( < .*?([^\.]+) \( (.+) \) > \) >", repr(pool), re.VERBOSE
).groups() == (
"ConnectionPool",
"UnixDomainSocketConnection",
"path=/path/to/socket,db=0",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asyncio/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@ def __init__(self, *args, **kwargs):
pass

lock = r.lock("foo", lock_class=MyLock)
assert type(lock) == MyLock
assert isinstance(lock, MyLock)
1 change: 0 additions & 1 deletion tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ def test_json_forget_with_dollar(client):
client.json().forget("not_a_document", "..a")


@pytest.mark.onlynoncluster
@pytest.mark.redismod
def test_json_mget_dollar(client):
# Test mget with multi paths
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ def __init__(self, *args, **kwargs):
pass

lock = r.lock("foo", lock_class=MyLock)
assert type(lock) == MyLock
assert isinstance(lock, MyLock)

0 comments on commit 97095cc

Please sign in to comment.