fix: use Python 3.9 compatible builtin generics

- Convert List[str] to list[str], Dict[str, Any] to dict[str, Any], etc.
- Use ruff --unsafe-fixes to automatically apply all type annotation updates
- Remove deprecated typing imports (List, Dict, Tuple) where no longer needed
- Keep Optional[str] syntax (union operator | not supported in Python 3.9)

Now all type annotations are Python 3.9 compatible with modern builtin generics.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Andy Lee
2025-08-10 00:38:33 +00:00
parent ffba435252
commit 6d1ac4a503
11 changed files with 49 additions and 49 deletions

View File

@@ -4,7 +4,7 @@ import os
import struct
import sys
from pathlib import Path
from typing import Any, Dict, List, Literal, Optional, Tuple
from typing import Any, Literal, Optional
import numpy as np
import psutil
@@ -85,7 +85,7 @@ def _write_vectors_to_bin(data: np.ndarray, file_path: Path):
f.write(data.tobytes())
def _calculate_smart_memory_config(data: np.ndarray) -> Tuple[float, float]:
def _calculate_smart_memory_config(data: np.ndarray) -> tuple[float, float]:
"""
Calculate smart memory configuration for DiskANN based on data size and system specs.
@@ -202,7 +202,7 @@ class DiskannBuilder(LeannBackendBuilderInterface):
size_mb = file_path.stat().st_size / (1024 * 1024)
logger.info(f" - {filename} ({size_mb:.1f} MB)")
def build(self, data: np.ndarray, ids: List[str], index_path: str, **kwargs):
def build(self, data: np.ndarray, ids: list[str], index_path: str, **kwargs):
path = Path(index_path)
index_dir = path.parent
index_prefix = path.stem
@@ -388,7 +388,7 @@ class DiskannSearcher(BaseSearcher):
batch_recompute: bool = False,
dedup_node_dis: bool = False,
**kwargs,
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""
Search for nearest neighbors using DiskANN index.

View File

@@ -12,7 +12,7 @@ import shutil
import subprocess
import tempfile
from pathlib import Path
from typing import Optional, Tuple
from typing import Optional
class GraphPartitioner:
@@ -92,7 +92,7 @@ class GraphPartitioner:
output_dir: Optional[str] = None,
partition_prefix: Optional[str] = None,
**kwargs,
) -> Tuple[str, str]:
) -> tuple[str, str]:
"""
Partition a disk-based index for improved performance.
@@ -267,7 +267,7 @@ def partition_graph(
partition_prefix: Optional[str] = None,
build_type: str = "release",
**kwargs,
) -> Tuple[str, str]:
) -> tuple[str, str]:
"""
Convenience function to partition a graph index.

View File

@@ -15,7 +15,7 @@ from typing import Optional
def partition_graph_simple(
index_prefix_path: str, output_dir: Optional[str] = None, **kwargs
) -> Tuple[str, str]:
) -> tuple[str, str]:
"""
Simple function to partition a graph index.