From 75660c29019afcf330e1fea872c2997f79463a50 Mon Sep 17 00:00:00 2001 From: GilboaAWS Date: Sun, 26 May 2024 07:48:30 +0000 Subject: [PATCH] addressed `Run isort . --profile black --check --diff` --- python/python/glide/__init__.py | 4 +- .../glide/async_commands/cluster_commands.py | 2 +- python/python/glide/async_commands/core.py | 10 ++- .../async_commands/standalone_commands.py | 2 +- .../glide/async_commands/transaction.py | 10 +-- python/python/tests/test_async_client.py | 73 ++++++++++--------- 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/python/python/glide/__init__.py b/python/python/glide/__init__.py index a8929e428e..b9e587c0e4 100644 --- a/python/python/glide/__init__.py +++ b/python/python/glide/__init__.py @@ -9,12 +9,12 @@ GeoUnit, InfoSection, InsertPosition, + SortOrder, StreamAddOptions, StreamTrimOptions, TrimByMaxLen, TrimByMinId, UpdateOptions, - SortOrder, ) from glide.async_commands.redis_modules import json from glide.async_commands.sorted_set import ( @@ -103,12 +103,12 @@ "RangeByLex", "RangeByScore", "ScoreFilter", + "SortOrder", "StreamAddOptions", "StreamTrimOptions", "TrimByMaxLen", "TrimByMinId", "UpdateOptions", - "SortOrder", # Logger "Logger", "LogLevel", diff --git a/python/python/glide/async_commands/cluster_commands.py b/python/python/glide/async_commands/cluster_commands.py index 93c3410381..67eb71b45b 100644 --- a/python/python/glide/async_commands/cluster_commands.py +++ b/python/python/glide/async_commands/cluster_commands.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Dict, List, Mapping, Optional, cast, Tuple +from typing import Dict, List, Mapping, Optional, Tuple, cast from glide.async_commands.core import ( CoreCommands, diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 1a79a9c2ca..1240995458 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -139,13 +139,17 @@ class UpdateOptions(Enum): class SortOrder(Enum): """ SORT order options: options for sorting elements. - - - ASC: Sort in ascending order. - - DESC: Sort in descending order. """ ASC = "ASC" + """ + ASC: Sort in ascending order. + """ + DESC = "DESC" + """ + DESC: Sort in descending order. + """ class GeospatialData: diff --git a/python/python/glide/async_commands/standalone_commands.py b/python/python/glide/async_commands/standalone_commands.py index dcfb35ed2b..860e9b8358 100644 --- a/python/python/glide/async_commands/standalone_commands.py +++ b/python/python/glide/async_commands/standalone_commands.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Dict, List, Mapping, Optional, cast, Tuple +from typing import Dict, List, Mapping, Optional, Tuple, cast from glide.async_commands.core import ( CoreCommands, diff --git a/python/python/glide/async_commands/transaction.py b/python/python/glide/async_commands/transaction.py index 47b66867a3..a9bc50e87b 100644 --- a/python/python/glide/async_commands/transaction.py +++ b/python/python/glide/async_commands/transaction.py @@ -11,10 +11,10 @@ GeoUnit, InfoSection, InsertPosition, + SortOrder, StreamAddOptions, StreamTrimOptions, UpdateOptions, - SortOrder, _build_sort_args, ) from glide.async_commands.sorted_set import ( @@ -2543,12 +2543,12 @@ class ClusterTransaction(BaseTransaction): """ def sort( - self, + self: TTransaction, key: str, limit: Optional[Tuple[int, int]] = None, order: Optional[SortOrder] = None, alpha: Optional[bool] = None, - ) -> List[Optional[str]]: + ) -> TTransaction: """ Sorts the elements in the list, set, or sorted set at `key` and returns the result. To store the result into a new key, see `sort_store`. @@ -2568,13 +2568,13 @@ def sort( return self.append_command(RequestType.Sort, args) def sort_store( - self, + self: TTransaction, key: str, store: str, limit: Optional[Tuple[int, int]] = None, order: Optional[SortOrder] = None, alpha: Optional[bool] = None, - ) -> int: + ) -> TTransaction: """ Sorts the elements in the list, set, or sorted set at `key` and stores the result in `store`. When in cluster mode, `key` and `store` must map to the same hash slot. diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 722260ceb7..91b89efcad 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -21,11 +21,11 @@ InfBound, InfoSection, InsertPosition, + SortOrder, StreamAddOptions, TrimByMaxLen, TrimByMinId, UpdateOptions, - SortOrder, ) from glide.async_commands.sorted_set import ( AggregationType, @@ -3198,38 +3198,39 @@ async def test_sort_and_sort_store_with_get_or_by_args( assert await redis_client.hset(user_key5, {"name": "Eve", "age": "40"}) == 2 assert await redis_client.lpush("user_ids", ["5", "4", "3", "2", "1"]) == 5 - # Test sort with all arguments - assert await redis_client.lpush(key, ["3", "1", "2"]) == 3 - result = await redis_client.sort( - key, - limit=(0, 2), - get_patterns=["user:*->name"], - order=SortOrder.ASC, - alpha=True, - ) - assert result == ["Alice", "Bob"] + if isinstance(redis_client, RedisClient): + # Test sort with all arguments + assert await redis_client.lpush(key, ["3", "1", "2"]) == 3 + result = await redis_client.sort( + key, + limit=(0, 2), + get_patterns=["user:*->name"], + order=SortOrder.ASC, + alpha=True, + ) + assert result == ["Alice", "Bob"] - # Test sort_store with all arguments - result = await redis_client.sort_store( - key, - store, - limit=(0, 2), - get_patterns=["user:*->name"], - order=SortOrder.ASC, - alpha=True, - ) - assert result == 2 - sorted_list = await redis_client.lrange(store, 0, -1) - assert sorted_list == ["Alice", "Bob"] + # Test sort_store with all arguments + sort_store_result = await redis_client.sort_store( + key, + store, + limit=(0, 2), + get_patterns=["user:*->name"], + order=SortOrder.ASC, + alpha=True, + ) + assert sort_store_result == 2 + sorted_list = await redis_client.lrange(store, 0, -1) + assert sorted_list == ["Alice", "Bob"] - # Test sort with `by` argument - result = await redis_client.sort( - "user_ids", - by_pattern="user:*->age", - get_patterns=["user:*->name"], - alpha=True, - ) - assert result == ["Dave", "Bob", "Alice", "Charlie", "Eve"] + # Test sort with `by` argument + result = await redis_client.sort( + "user_ids", + by_pattern="user:*->age", + get_patterns=["user:*->name"], + alpha=True, + ) + assert result == ["Dave", "Bob", "Alice", "Charlie", "Eve"] @pytest.mark.parametrize("cluster_mode", [True, False]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) @@ -3244,8 +3245,10 @@ async def test_sort_and_sort_store_without_get_or_by_args( assert result == [] # Test sort_store with non-existing key - result = await redis_client.sort_store("{SameSlotKey}:non_existing_key", store) - assert result == 0 + sort_store_result = await redis_client.sort_store( + "{SameSlotKey}:non_existing_key", store + ) + assert sort_store_result == 0 # Test each argument separately assert await redis_client.lpush(key, ["5", "2", "4", "1", "3"]) == 5 @@ -3279,10 +3282,10 @@ async def test_sort_and_sort_store_without_get_or_by_args( assert result == ["5", "4", "3"] # Test sort_store with combined arguments - result = await redis_client.sort_store( + sort_store_result = await redis_client.sort_store( key, store, limit=(1, 3), order=SortOrder.DESC, alpha=True ) - assert result == 3 + assert sort_store_result == 3 sorted_list = await redis_client.lrange(store, 0, -1) assert sorted_list == ["5", "4", "3"]