Skip to content

Commit 217d213

Browse files
committed
chore: silence UP045 on Optional for py3.9
Signed-off-by: Arya Tayshete <[email protected]>
1 parent 3cf8a37 commit 217d213

File tree

1 file changed

+9
-7
lines changed
  • integrations/fastembed/src/haystack_integrations/components/rankers/fastembed

1 file changed

+9
-7
lines changed

integrations/fastembed/src/haystack_integrations/components/rankers/fastembed/colbert_reranker.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
from __future__ import annotations
55

6-
from typing import Any, Sequence, Optional, TYPE_CHECKING
6+
from typing import TYPE_CHECKING, Any, Iterator, Optional, Sequence
7+
78
import numpy as np
89
from haystack import Document, component
910

@@ -89,7 +90,7 @@ def __init__(
8990
msg = f"batch_size must be > 0, got {batch_size}"
9091
raise ValueError(msg)
9192

92-
self._encoder: Optional["LateInteractionTextEmbedding"] = None # LateInteractionTextEmbedding
93+
self._encoder: Optional[LateInteractionTextEmbedding] = None # LateInteractionTextEmbedding # noqa: UP045
9394
self._ready = False
9495

9596
def warm_up(self):
@@ -106,10 +107,10 @@ def warm_up(self):
106107
max_tokens_query=self.max_query_tokens,
107108
max_tokens_document=self.max_doc_tokens,
108109
)
109-
gen_q = self._encoder.query_embed(["warmup"])
110-
next(gen_q, None)
111-
gen_d = self._encoder.embed(["warmup"])
112-
next(gen_d, None)
110+
gen_q_iter: Iterator[np.ndarray] = iter(self._encoder.query_embed(["warmup"]))
111+
next(gen_q_iter, None)
112+
gen_d_iter: Iterator[np.ndarray] = iter(self._encoder.embed(["warmup"]))
113+
next(gen_d_iter, None)
113114

114115
self._ready = True
115116
except ModuleNotFoundError as e:
@@ -134,7 +135,8 @@ def _encode_query(self, text: str) -> np.ndarray:
134135
if self._encoder is None:
135136
msg = "Encoder is not initialized. Call warm_up() first."
136137
raise RuntimeError(msg)
137-
arr = next(self._encoder.query_embed([text]), None)
138+
it: Iterator[np.ndarray] = iter(self._encoder.query_embed([text]))
139+
arr = next(it, None)
138140
if arr is None:
139141
return np.zeros((0, 0), dtype=np.float32)
140142
a = np.asarray(arr, dtype=np.float32)

0 commit comments

Comments
 (0)