From dcd6da0a3eb1ffb9ff0bcc8f4104d6bd4619a87c Mon Sep 17 00:00:00 2001 From: avifenesh Date: Fri, 28 Jun 2024 09:39:42 +0000 Subject: [PATCH] fixed typing --- python/python/glide/constants.py | 1 - python/python/tests/test_async_client.py | 126 +++++++++++++---------- 2 files changed, 70 insertions(+), 57 deletions(-) diff --git a/python/python/glide/constants.py b/python/python/glide/constants.py index 398caa1946..f78398895a 100644 --- a/python/python/glide/constants.py +++ b/python/python/glide/constants.py @@ -22,7 +22,6 @@ float, Set[T], List[T], - List[Union[str, List[str]]], ] TRequest = Union[RedisRequest, ConnectionRequest] # When routing to a single node, response will be T diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 1f566a5159..58cc92ac28 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -6676,11 +6676,12 @@ async def test_simple_cluster_scan(self, redis_client: GlideClusterClient): for key in expected_keys: await redis_client.set(key, "value") cursor = ClusterScanCursor(None) - keys = [] + keys: list[str] = [] while not cursor.is_finished(): result = await redis_client.scan(cursor) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(ClusterScanCursor, result[0]) + result_keys = cast(list[str], result[1]) + keys.extend(result_keys) assert set(expected_keys) == set(keys) @@ -6698,14 +6699,15 @@ async def test_cluster_scan_with_object_type_and_pattern( unexpected_pattern_keys = [f"{i}" for i in range(200, 300)] for key in unexpected_pattern_keys: await redis_client.set(key, "value") - keys = [] + keys: list[str] = [] cursor = ClusterScanCursor(None) while not cursor.is_finished(): result = await redis_client.scan( cursor, match="key:*", type=ObjectType.STRING ) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(ClusterScanCursor, result[0]) + result_keys = cast(list[str], result[1]) + keys.extend(result_keys) assert set(expected_keys) == set(keys) assert not set(unexpected_type_keys).intersection(set(keys)) @@ -6718,20 +6720,20 @@ async def test_cluster_scan_with_count(self, redis_client: GlideClusterClient): for key in expected_keys: await redis_client.set(key, "value") cursor = ClusterScanCursor(None) - keys = [] + keys: list[str] = [] succefull_compared_scans = 0 while not cursor.is_finished(): result_of_1 = await redis_client.scan(cursor, count=1) - cursor = result_of_1[0] - keys_of_1 = result_of_1[1] - keys.extend(keys_of_1) + cursor = cast(ClusterScanCursor, result_of_1[0]) + result_keys_of_1 = cast(list[str], result_of_1[1]) + keys.extend(result_keys_of_1) if cursor.is_finished(): break result_of_100 = await redis_client.scan(cursor, count=100) - cursor = result_of_100[0] - keys_of_100 = result_of_100[1] - keys.extend(keys_of_100) - if keys_of_100 > keys_of_1: + cursor = cast(ClusterScanCursor, result_of_100[0]) + result_keys_of_100 = cast(list[str], result_of_100[1]) + keys.extend(result_keys_of_100) + if len(result_keys_of_100) > len(result_keys_of_1): succefull_compared_scans += 1 assert set(expected_keys) == set(keys) @@ -6747,11 +6749,12 @@ async def test_cluster_scan_with_match(self, redis_client: GlideClusterClient): for key in expected_keys: await redis_client.set(key, "value") cursor = ClusterScanCursor(None) - keys = [] + keys: list[str] = [] while not cursor.is_finished(): result = await redis_client.scan(cursor, match="key:*") - cursor = result[0] - keys.extend(result[1]) + cursor = cast(ClusterScanCursor, result[0]) + result_keys = cast(list[str], result[1]) + keys.extend(result_keys) assert set(expected_keys) == set(keys) assert not set(unexpected_keys).intersection(set(keys)) @@ -6764,7 +6767,7 @@ async def test_cluster_scan_cleaning_cursor(self, redis_client: GlideClusterClie await redis_client.set(key, "value") cursor = ClusterScanCursor(None) result = await redis_client.scan(cursor) - cursor = result[0] + cursor = cast(ClusterScanCursor, result[0]) cursor_string = str(cursor) cursor.__del__() new_cursor_with_same_id = ClusterScanCursor(cursor_string) @@ -6797,11 +6800,12 @@ async def test_cluster_scan_all_types(self, redis_client: GlideClusterClient): await redis_client.zadd(key, {"value": 1}) cursor = ClusterScanCursor(None) - keys = [] + keys: list[str] = [] while not cursor.is_finished(): result = await redis_client.scan(cursor, type=ObjectType.STRING) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(ClusterScanCursor, result[0]) + result_keys = cast(list[str], result[1]) + keys.extend(result_keys) assert set(string_keys) == set(keys) assert not set(set_keys).intersection(set(keys)) assert not set(hash_keys).intersection(set(keys)) @@ -6809,11 +6813,12 @@ async def test_cluster_scan_all_types(self, redis_client: GlideClusterClient): assert not set(zset_keys).intersection(set(keys)) cursor = ClusterScanCursor(None) - keys = [] + keys.clear() while not cursor.is_finished(): result = await redis_client.scan(cursor, type=ObjectType.SET) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(ClusterScanCursor, result[0]) + result_keys = cast(list[str], result[1]) + keys.extend(result_keys) assert set(set_keys) == set(keys) assert not set(string_keys).intersection(set(keys)) assert not set(hash_keys).intersection(set(keys)) @@ -6821,11 +6826,12 @@ async def test_cluster_scan_all_types(self, redis_client: GlideClusterClient): assert not set(zset_keys).intersection(set(keys)) cursor = ClusterScanCursor(None) - keys = [] + keys.clear() while not cursor.is_finished(): result = await redis_client.scan(cursor, type=ObjectType.HASH) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(ClusterScanCursor, result[0]) + result_keys = cast(list[str], result[1]) + keys.extend(result_keys) assert set(hash_keys) == set(keys) assert not set(string_keys).intersection(set(keys)) assert not set(set_keys).intersection(set(keys)) @@ -6833,11 +6839,12 @@ async def test_cluster_scan_all_types(self, redis_client: GlideClusterClient): assert not set(zset_keys).intersection(set(keys)) cursor = ClusterScanCursor(None) - keys = [] + keys.clear() while not cursor.is_finished(): result = await redis_client.scan(cursor, type=ObjectType.LIST) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(ClusterScanCursor, result[0]) + result_keys = cast(list[str], result[1]) + keys.extend(result_keys) assert set(list_keys) == set(keys) assert not set(string_keys).intersection(set(keys)) assert not set(set_keys).intersection(set(keys)) @@ -6851,12 +6858,13 @@ async def test_simple_scan(self, redis_client: GlideClient): expected_keys = [f"key:{i}" for i in range(100)] for key in expected_keys: await redis_client.set(key, "value") - keys = [] + keys: list[str] = [] cursor = 0 while True: result = await redis_client.scan(cursor) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(int, result[0]) + new_keys = cast(list[str], result[1]) + keys.extend(new_keys) if cursor == 0: break assert set(expected_keys) == set(keys) @@ -6873,14 +6881,15 @@ async def test_scan_with_object_type_and_pattern(self, redis_client: GlideClient unexpected_pattern_keys = [f"{i}" for i in range(200, 300)] for key in unexpected_pattern_keys: await redis_client.set(key, "value") - keys = [] + keys: list[str] = [] cursor = 0 while True: result = await redis_client.scan( cursor, match="key:*", type=ObjectType.STRING ) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(int, result[0]) + new_keys = cast(list[str], result[1]) + keys.extend(new_keys) if cursor == 0: break assert set(expected_keys) == set(keys) @@ -6894,16 +6903,16 @@ async def test_scan_with_count(self, redis_client: GlideClient): for key in expected_keys: await redis_client.set(key, "value") cursor = 0 - keys = [] + keys: list[str] = [] succefull_compared_scans = 0 while True: result_of_1 = await redis_client.scan(cursor, count=1) - cursor = result_of_1[0] - keys_of_1 = result_of_1[1] + cursor = cast(int, result_of_1[0]) + keys_of_1 = cast(list[str], result_of_1[1]) keys.extend(keys_of_1) result_of_100 = await redis_client.scan(cursor, count=100) - cursor = result_of_100[0] - keys_of_100 = result_of_100[1] + cursor = cast(int, result_of_100[0]) + keys_of_100 = cast(list[str], result_of_100[1]) keys.extend(keys_of_100) if keys_of_100 > keys_of_1: succefull_compared_scans += 1 @@ -6922,11 +6931,12 @@ async def test_cluster_with_match(self, redis_client: GlideClient): for key in expected_keys: await redis_client.set(key, "value") cursor = 0 - keys = [] + keys: list[str] = [] while True: result = await redis_client.scan(cursor, match="key:*") - cursor = result[0] - keys.extend(result[1]) + cursor = cast(int, result[0]) + new_keys = cast(list[str], result[1]) + keys.extend(new_keys) if cursor == 0: break assert set(expected_keys) == set(keys) @@ -6957,11 +6967,12 @@ async def test_scan_all_types(self, redis_client: GlideClient): await redis_client.zadd(key, {"value": 1}) cursor = 0 - keys = [] + keys: list[str] = [] while True: result = await redis_client.scan(cursor, type=ObjectType.STRING) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(int, result[0]) + new_keys = cast(list[str], result[1]) + keys.extend(new_keys) if cursor == 0: break assert set(string_keys) == set(keys) @@ -6971,11 +6982,12 @@ async def test_scan_all_types(self, redis_client: GlideClient): assert not set(zset_keys).intersection(set(keys)) cursor = 0 - keys = [] + keys.clear() while True: result = await redis_client.scan(cursor, type=ObjectType.SET) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(int, result[0]) + new_keys = cast(list[str], result[1]) + keys.extend(new_keys) if cursor == 0: break assert set(set_keys) == set(keys) @@ -6985,11 +6997,12 @@ async def test_scan_all_types(self, redis_client: GlideClient): assert not set(zset_keys).intersection(set(keys)) cursor = 0 - keys = [] + keys.clear() while True: result = await redis_client.scan(cursor, type=ObjectType.HASH) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(int, result[0]) + new_keys = cast(list[str], result[1]) + keys.extend(new_keys) if cursor == 0: break assert set(hash_keys) == set(keys) @@ -6999,11 +7012,12 @@ async def test_scan_all_types(self, redis_client: GlideClient): assert not set(zset_keys).intersection(set(keys)) cursor = 0 - keys = [] + keys.clear() while True: result = await redis_client.scan(cursor, type=ObjectType.LIST) - cursor = result[0] - keys.extend(result[1]) + cursor = cast(int, result[0]) + new_keys = cast(list[str], result[1]) + keys.extend(new_keys) if cursor == 0: break assert set(list_keys) == set(keys)