Skip to content

Commit a98dcde

Browse files
authored
chore: remove unused imports and variables (#538)
- Remove unused imports: Union, ClusterPipeline, AsyncClusterPipeline, logging, cast, Optional, os, lazy_import, SyncRedisCluster, Mapping, Awaitable, warnings - Fix unused exception variables in index.py exception handlers - Clean up HybridResult import used only for feature detection <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk cleanup-only change: removes unused imports/variables and minor exception-handler refactors without altering core control flow or Redis commands. > > **Overview** > Removes a set of unused imports across CLI, cache, router, query, storage, vectorize, and protocol helper modules to satisfy linters and reduce dead dependencies. > > Cleans up `SearchIndex`/`AsyncSearchIndex` exception handling to avoid unused exception variables, and tweaks hybrid-search feature detection by importing `HybridResult` under an alias purely to confirm availability. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3fab84b. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 02ba7b2 commit a98dcde

10 files changed

Lines changed: 19 additions & 33 deletions

File tree

redisvl/cli/stats.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from redisvl.index import SearchIndex
77
from redisvl.schema.schema import IndexSchema
88
from redisvl.utils.log import get_logger
9-
from redisvl.utils.utils import lazy_import
109

1110
logger = get_logger("[RedisVL]")
1211

redisvl/extensions/cache/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"""
66

77
from collections.abc import Mapping
8-
from typing import Any, Dict, Optional, Union
8+
from typing import Any, Dict, Optional
99

1010
from redis import Redis # For backwards compatibility in type checking
1111
from redis.cluster import RedisCluster
1212

1313
from redisvl.redis.connection import RedisConnectionFactory
14-
from redisvl.types import AsyncRedisClient, SyncRedisClient, SyncRedisCluster
14+
from redisvl.types import AsyncRedisClient, SyncRedisClient
1515

1616

1717
class BaseCache:

redisvl/extensions/router/semantic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from typing import Any, Dict, List, Mapping, Optional, Type, Union
2+
from typing import Any, Dict, List, Optional, Type, Union
33

44
import redis.commands.search.reducers as reducers
55
import yaml

redisvl/index/index.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ def _validate_query(self, query: BaseQuery) -> None:
286286
def _validate_hybrid_query(self, query: Any) -> None:
287287
"""Validate that a hybrid query can be executed."""
288288
try:
289-
from redis.commands.search.hybrid_result import HybridResult
289+
from redis.commands.search.hybrid_result import ( # noqa: F401
290+
HybridResult as _HybridResult,
291+
)
290292

291293
from redisvl.query.hybrid import HybridQuery
294+
295+
del _HybridResult # Only imported to check availability
292296
except (ImportError, ModuleNotFoundError):
293297
raise ImportError(_HYBRID_SEARCH_ERROR_MESSAGE)
294298

@@ -894,14 +898,14 @@ def load(
894898
batch_size=batch_size,
895899
validate=self._validate_on_load,
896900
)
897-
except SchemaValidationError as e:
901+
except SchemaValidationError:
898902
# Log the detailed validation error with actionable information
899903
logger.error("Data validation failed during load operation")
900904
raise
901-
except Exception as e:
905+
except Exception as exc:
902906
# Wrap other errors as general RedisVL errors
903907
logger.exception("Error while loading data to Redis")
904-
raise RedisVLError(f"Failed to load data: {str(e)}") from e
908+
raise RedisVLError(f"Failed to load data: {str(exc)}") from exc
905909

906910
def fetch(self, id: str) -> Optional[Dict[str, Any]]:
907911
"""Fetch an object from Redis by id.
@@ -1840,14 +1844,14 @@ def add_field(d):
18401844
batch_size=batch_size,
18411845
validate=self._validate_on_load,
18421846
)
1843-
except SchemaValidationError as e:
1847+
except SchemaValidationError:
18441848
# Log the detailed validation error with actionable information
18451849
logger.error("Data validation failed during load operation")
18461850
raise
1847-
except Exception as e:
1851+
except Exception as exc:
18481852
# Wrap other errors as general RedisVL errors
18491853
logger.exception("Error while loading data to Redis")
1850-
raise RedisVLError(f"Failed to load data: {str(e)}") from e
1854+
raise RedisVLError(f"Failed to load data: {str(exc)}") from exc
18511855

18521856
async def fetch(self, id: str) -> Optional[Dict[str, Any]]:
18531857
"""Asynchronously etch an object from Redis by id. The id is typically

redisvl/index/storage.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
from collections.abc import Collection
2-
from typing import (
3-
Any,
4-
Awaitable,
5-
Callable,
6-
Dict,
7-
Iterable,
8-
List,
9-
Optional,
10-
Tuple,
11-
Union,
12-
cast,
13-
)
2+
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
143

154
from pydantic import BaseModel, ValidationError
165
from redis import __version__ as redis_version

redisvl/query/aggregate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import warnings
21
from typing import Any, Dict, List, Optional, Set, Union
32

43
from pydantic import BaseModel, Field, field_validator, model_validator

redisvl/utils/redis_protocol.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
This fixes issue #365 where ClusterPipeline objects may not have nodes_manager attribute.
55
"""
66

7-
from typing import Optional, Union
7+
from typing import Optional
88

9-
from redis.asyncio.cluster import ClusterPipeline as AsyncClusterPipeline
10-
from redis.cluster import ClusterPipeline
119
from redis.commands.helpers import get_protocol_version as redis_get_protocol_version
1210

1311

redisvl/utils/rerank/hf_cross_encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional, Tuple, Union
1+
from typing import Any, Dict, List, Tuple, Union
22

33
from pydantic import PrivateAttr
44

redisvl/utils/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import importlib
33
import inspect
44
import json
5-
import logging
65
import sys
76
import warnings
87
from contextlib import contextmanager
98
from enum import Enum
109
from functools import wraps
1110
from time import time
12-
from typing import Any, Callable, Coroutine, Dict, Optional, Sequence, TypeVar, cast
11+
from typing import Any, Callable, Coroutine, Dict, Optional, Sequence, TypeVar
1312
from warnings import warn
1413

1514
from pydantic import BaseModel
@@ -238,7 +237,7 @@ def wrapper():
238237
asyncio.set_event_loop(loop)
239238
task = loop.create_task(fn())
240239
loop.run_until_complete(task)
241-
except (RuntimeError, AttributeError, TypeError) as e:
240+
except (RuntimeError, AttributeError, TypeError):
242241
# This could happen if an object stored an event loop and now
243242
# that event loop is closed, or if asyncio modules are being
244243
# torn down during interpreter shutdown.

redisvl/utils/vectorize/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
from redisvl.extensions.cache.embeddings import EmbeddingsCache
42
from redisvl.utils.vectorize.base import BaseVectorizer, Vectorizers
53
from redisvl.utils.vectorize.bedrock import BedrockVectorizer

0 commit comments

Comments
 (0)