fix: Python 3.9 compatibility - replace union types and builtin generics

- Replace 'str | None' with 'Optional[str]'
- Replace 'list[str]' with 'List[str]'
- Replace 'dict[' with 'Dict['
- Replace 'tuple[' with 'Tuple['
- Add missing typing imports (List, Dict, Tuple)

Fixes TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

🤖 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:29:46 +00:00
parent 728fa42ad5
commit ffba435252
13 changed files with 59 additions and 58 deletions

View File

@@ -4,7 +4,7 @@ import os
import struct
import sys
from pathlib import Path
from typing import Any, Literal, Optional
from typing import Any, Dict, List, Literal, Optional, Tuple
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
from typing import Optional, Tuple
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.
@@ -263,11 +263,11 @@ class GraphPartitioner:
def partition_graph(
index_prefix_path: str,
output_dir: str | None = None,
partition_prefix: str | None = None,
output_dir: Optional[str] = None,
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.