From 22a287ce1ab630ec47d08ce975cab4be2dc74c6a Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:03:42 +0300 Subject: [PATCH] Python - type() fix --- python/python/pybushka/routes.py | 10 +++++----- python/python/tests/test_config.py | 2 +- python/python/tests/test_transaction.py | 20 ++++++++++++++------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/python/python/pybushka/routes.py b/python/python/pybushka/routes.py index c869fea5ea..998d4a8662 100644 --- a/python/python/pybushka/routes.py +++ b/python/python/pybushka/routes.py @@ -57,16 +57,16 @@ def to_protobuf_slot_type(slot_type: SlotType) -> ProtoSlotTypes.ValueType: def set_protobuf_route(request: RedisRequest, route: Optional[Route]) -> None: if route is None: return - elif type(route) == AllNodes: + elif isinstance(route, AllNodes): request.route.simple_routes = SimpleRoutes.AllNodes - elif type(route) == AllPrimaries: + elif isinstance(route, AllPrimaries): request.route.simple_routes = SimpleRoutes.AllPrimaries - elif type(route) == RandomNode: + elif isinstance(route, RandomNode): request.route.simple_routes = SimpleRoutes.Random - elif type(route) == SlotKeyRoute: + elif isinstance(route, SlotKeyRoute): request.route.slot_key_route.slot_type = to_protobuf_slot_type(route.slot_type) request.route.slot_key_route.slot_key = route.slot_key - elif type(route) == SlotIdRoute: + elif isinstance(route, SlotIdRoute): request.route.slot_id_route.slot_type = to_protobuf_slot_type(route.slot_type) request.route.slot_id_route.slot_id = route.slot_id else: diff --git a/python/python/tests/test_config.py b/python/python/tests/test_config.py index daae730fd8..15bb01638d 100644 --- a/python/python/tests/test_config.py +++ b/python/python/tests/test_config.py @@ -21,7 +21,7 @@ def test_convert_to_protobuf(): read_from_replica=ReadFromReplica.ROUND_ROBIN, ) request = config._create_a_protobuf_conn_request() - assert type(request) == ConnectionRequest + assert isinstance(request, ConnectionRequest) assert request.addresses[0].host == "127.0.0.1" assert request.addresses[0].port == 6379 assert request.tls_mode is TlsMode.SecureTls diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index 6ba6781715..570ff8f487 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -72,7 +72,9 @@ class TestTransaction: @pytest.mark.parametrize("cluster_mode", [True]) async def test_transaction_with_different_slots(self, redis_client: TRedisClient): transaction = ( - Transaction() if type(redis_client) == RedisClient else ClusterTransaction() + Transaction() + if isinstance(redis_client, RedisClient) + else ClusterTransaction() ) transaction.set("key1", "value1") transaction.set("key2", "value2") @@ -84,7 +86,9 @@ async def test_transaction_with_different_slots(self, redis_client: TRedisClient async def test_transaction_custom_command(self, redis_client: TRedisClient): key = get_random_string(10) transaction = ( - Transaction() if type(redis_client) == RedisClient else ClusterTransaction() + Transaction() + if isinstance(redis_client, RedisClient) + else ClusterTransaction() ) transaction.custom_command(["HSET", key, "foo", "bar"]) transaction.custom_command(["HGET", key, "foo"]) @@ -97,7 +101,9 @@ async def test_transaction_custom_unsupported_command( ): key = get_random_string(10) transaction = ( - Transaction() if type(redis_client) == RedisClient else ClusterTransaction() + Transaction() + if isinstance(redis_client, RedisClient) + else ClusterTransaction() ) transaction.custom_command(["WATCH", key]) with pytest.raises(Exception) as e: @@ -111,7 +117,9 @@ async def test_transaction_discard_command(self, redis_client: TRedisClient): key = get_random_string(10) await redis_client.set(key, "1") transaction = ( - Transaction() if type(redis_client) == RedisClient else ClusterTransaction() + Transaction() + if isinstance(redis_client, RedisClient) + else ClusterTransaction() ) transaction.custom_command(["INCR", key]) @@ -140,7 +148,7 @@ async def test_cluster_transaction(self, redis_client: RedisClusterClient): transaction.info() expected = transaction_test(transaction, keyslot) result = await redis_client.exec(transaction) - assert type(result[0]) == str + assert isinstance(result[0], str) assert "# Memory" in result[0] assert result[1:] == expected @@ -158,7 +166,7 @@ async def test_standalone_transaction(self, redis_client: RedisClient): transaction.get(key) expected = transaction_test(transaction, keyslot) result = await redis_client.exec(transaction) - assert type(result[0]) == str + assert isinstance(result[0], str) assert "# Memory" in result[0] assert result[1:6] == [OK, OK, value, OK, None] assert result[6:] == expected