Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Oct 2, 2023
1 parent 1b6f9cc commit e23db3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/elasticsearch_haystack/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,14 @@ def write_documents(self, documents: List[Document], policy: DuplicatePolicy = D
index=self._index,
raise_on_error=False,
)

if errors and policy == DuplicatePolicy.FAIL:
# TODO: Handle errors in a better way, we're assuming that all errors
# are related to duplicate documents but that could be very well be wrong.
ids = ", ".join(e["create"]["_id"] for e in errors)

# mypy complains that `errors`` could be either `int` or a `list` of `dict`s.
# Since the type depends on the parameters passed to `helpers.bulk()`` we know
# for sure that it will be a `list`.
ids = ", ".join(e["create"]["_id"] for e in errors) # type: ignore[union-attr]
msg = f"IDs '{ids}' already exist in the document store."
raise DuplicateDocumentError(msg)

Expand Down
4 changes: 2 additions & 2 deletions src/elasticsearch_haystack/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _normalize_filters(filters: Union[List[Dict], Dict], logical_condition="") -


def _parse_comparison(field: str, comparison: Union[Dict, List, str, float]) -> List:
result = []
result: List[Dict[str, Any]] = []
if isinstance(comparison, dict):
for comparator, val in comparison.items():
if comparator == "$eq":
Expand Down Expand Up @@ -125,7 +125,7 @@ def _normalize_ranges(conditions: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
range_conditions = [next(iter(c["range"].items())) for c in conditions if "range" in c]
if range_conditions:
conditions = [c for c in conditions if "range" not in c]
range_conditions_dict = {}
range_conditions_dict: Dict[str, Any] = {}
for field_name, comparison in range_conditions:
if field_name not in range_conditions_dict:
range_conditions_dict[field_name] = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestDocumentStore(DocumentStoreBaseTests):
"""

@pytest.fixture
def docstore(self, request) -> ElasticsearchDocumentStore:
def docstore(self, request):
"""
This is the most basic requirement for the child class: provide
an instance of this document store so the base class can use it.
Expand Down

0 comments on commit e23db3a

Please sign in to comment.