-
Notifications
You must be signed in to change notification settings - Fork 168
new: drop python3.9, replace optional and union with | #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7a41a17
f9d0d00
753aa2a
3d12ccd
985d185
5632fe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ jobs: | |
| strategy: | ||
| matrix: | ||
| python-version: | ||
| - '3.9.x' | ||
| - '3.10.x' | ||
| - '3.11.x' | ||
| - '3.12.x' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,20 @@ | ||
| from pathlib import Path | ||
| import sys | ||
| from PIL import Image | ||
| from typing import Any, Union | ||
|
|
||
| from typing import Any, TypeAlias | ||
| import numpy as np | ||
| from numpy.typing import NDArray | ||
|
|
||
| if sys.version_info >= (3, 10): | ||
| from typing import TypeAlias | ||
| else: | ||
| from typing_extensions import TypeAlias | ||
| from PIL import Image | ||
|
|
||
|
|
||
| PathInput: TypeAlias = Union[str, Path] | ||
| ImageInput: TypeAlias = Union[PathInput, Image.Image] | ||
| PathInput: TypeAlias = str | Path | ||
| ImageInput: TypeAlias = PathInput | Image.Image | ||
|
|
||
| OnnxProvider: TypeAlias = Union[str, tuple[str, dict[Any, Any]]] | ||
| NumpyArray = Union[ | ||
| NDArray[np.float64], | ||
| NDArray[np.float32], | ||
| NDArray[np.float16], | ||
| NDArray[np.int8], | ||
| NDArray[np.int64], | ||
| NDArray[np.int32], | ||
| ] | ||
| OnnxProvider: TypeAlias = str | tuple[str, dict[Any, Any]] | ||
| NumpyArray: TypeAlias = ( | ||
| NDArray[np.float64] | ||
| | NDArray[np.float32] | ||
| | NDArray[np.float16] | ||
| | NDArray[np.int8] | ||
| | NDArray[np.int64] | ||
| | NDArray[np.int32] | ||
| ) | ||
|
Comment on lines
+13
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find and examine the project's dependency specifications
find . -maxdepth 2 -type f \( -name "setup.py" -o -name "requirements.txt" -o -name "pyproject.toml" -o -name "setup.cfg" \) | head -20Repository: qdrant/fastembed Length of output: 76 🏁 Script executed: # Examine the current state of fastembed/common/types.py
cat -n fastembed/common/types.pyRepository: qdrant/fastembed Length of output: 652 🏁 Script executed: # Search for usages of NumpyArray alias in the codebase
rg "NumpyArray" --type py -B 2 -A 2Repository: qdrant/fastembed Length of output: 50372 🏁 Script executed: # Check if there are any recent changes or related issues with NDArray
git log --oneline --all --grep="NDArray\|NumpyArray" | head -20Repository: qdrant/fastembed Length of output: 42 🏁 Script executed: # Check numpy version requirements
cat pyproject.toml | grep -A 10 -B 2 "numpy\|python"Repository: qdrant/fastembed Length of output: 146 🏁 Script executed: # Try to import the types module to see if there are any immediate issues
python3 << 'EOF'
try:
import sys
sys.path.insert(0, '/repo')
from fastembed.common.types import NumpyArray
print("✓ NumpyArray imported successfully")
print(f"NumpyArray = {NumpyArray}")
except Exception as e:
print(f"✗ Import failed: {type(e).__name__}: {e}")
EOFRepository: qdrant/fastembed Length of output: 146 🏁 Script executed: # Examine the sparse_embedding_base.py file where the prior issue occurred
head -30 fastembed/sparse/sparse_embedding_base.pyRepository: qdrant/fastembed Length of output: 980 Use The current pipe operator syntax for Switch to from typing import Union
NumpyArray: TypeAlias = Union[
NDArray[np.float64],
NDArray[np.float32],
NDArray[np.float16],
NDArray[np.int8],
NDArray[np.int64],
NDArray[np.int32],
]Add a comment explaining why Union is preferred over the pipe operator for NDArray unions. 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid
NDArray[...] | Nonein dataclass fields; keepUnionhere.For
OnnxOutputContext, annotatingattention_maskandinput_idsasNDArray[np.int64] | Nonecan trigger runtime issues because dataclasses evaluate annotations at class creation time andNDArray[...]does not reliably support the|operator in this codebase. Based on prior experience, these fields should keeptyping.Union[...]instead of PEP 604 unions, with a short comment explaining why.A possible adjustment:
Based on learnings, this keeps the modernisation elsewhere while avoiding the known NDArray/dataclass pitfall.
📝 Committable suggestion
🤖 Prompt for AI Agents