|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from datetime import datetime |
4 | | -from typing import Any, Dict, Generator, List, Optional, Union |
| 4 | +from typing import Any, Dict, Generator, List, Mapping, MutableMapping, Optional, Sequence, Union |
5 | 5 | from urllib import parse |
6 | 6 | from warnings import warn |
7 | 7 |
|
@@ -118,7 +118,7 @@ def get_primary_key(self) -> str | None: |
118 | 118 | return self.fetch_info().primary_key |
119 | 119 |
|
120 | 120 | @staticmethod |
121 | | - def create(config: Config, uid: str, options: Optional[Dict[str, Any]] = None) -> TaskInfo: |
| 121 | + def create(config: Config, uid: str, options: Optional[Mapping[str, Any]] = None) -> TaskInfo: |
122 | 122 | """Create the index. |
123 | 123 |
|
124 | 124 | Parameters |
@@ -146,7 +146,7 @@ def create(config: Config, uid: str, options: Optional[Dict[str, Any]] = None) - |
146 | 146 |
|
147 | 147 | return TaskInfo(**task) |
148 | 148 |
|
149 | | - def get_tasks(self, parameters: Optional[Dict[str, Any]] = None) -> TaskResults: |
| 149 | + def get_tasks(self, parameters: Optional[MutableMapping[str, Any]] = None) -> TaskResults: |
150 | 150 | """Get all tasks of a specific index from the last one. |
151 | 151 |
|
152 | 152 | Parameters |
@@ -244,7 +244,7 @@ def get_stats(self) -> IndexStats: |
244 | 244 | return IndexStats(stats) |
245 | 245 |
|
246 | 246 | @version_error_hint_message |
247 | | - def search(self, query: str, opt_params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: |
| 247 | + def search(self, query: str, opt_params: Optional[Mapping[str, Any]] = None) -> Dict[str, Any]: |
248 | 248 | """Search in the index. |
249 | 249 |
|
250 | 250 | Parameters |
@@ -284,7 +284,7 @@ def facet_search( |
284 | 284 | self, |
285 | 285 | facet_name: str, |
286 | 286 | facet_query: Optional[str] = None, |
287 | | - opt_params: Optional[Dict[str, Any]] = None, |
| 287 | + opt_params: Optional[Mapping[str, Any]] = None, |
288 | 288 | ) -> Dict[str, Any]: |
289 | 289 | """ |
290 | 290 | Perform a facet search based on the given facet query and facet name. |
@@ -313,7 +313,7 @@ def facet_search( |
313 | 313 | ) |
314 | 314 |
|
315 | 315 | def get_document( |
316 | | - self, document_id: Union[str, int], parameters: Optional[Dict[str, Any]] = None |
| 316 | + self, document_id: Union[str, int], parameters: Optional[MutableMapping[str, Any]] = None |
317 | 317 | ) -> Document: |
318 | 318 | """Get one document with given document identifier. |
319 | 319 |
|
@@ -345,7 +345,9 @@ def get_document( |
345 | 345 | return Document(document) |
346 | 346 |
|
347 | 347 | @version_error_hint_message |
348 | | - def get_documents(self, parameters: Optional[Dict[str, Any]] = None) -> DocumentsResults: |
| 348 | + def get_documents( |
| 349 | + self, parameters: Optional[MutableMapping[str, Any]] = None |
| 350 | + ) -> DocumentsResults: |
349 | 351 | """Get a set of documents from the index. |
350 | 352 |
|
351 | 353 | Parameters |
@@ -387,7 +389,7 @@ def get_documents(self, parameters: Optional[Dict[str, Any]] = None) -> Document |
387 | 389 |
|
388 | 390 | def add_documents( |
389 | 391 | self, |
390 | | - documents: List[Dict[str, Any]], |
| 392 | + documents: Sequence[Mapping[str, Any]], |
391 | 393 | primary_key: Optional[str] = None, |
392 | 394 | ) -> TaskInfo: |
393 | 395 | """Add documents to the index. |
@@ -416,7 +418,7 @@ def add_documents( |
416 | 418 |
|
417 | 419 | def add_documents_in_batches( |
418 | 420 | self, |
419 | | - documents: List[Dict[str, Any]], |
| 421 | + documents: Sequence[Mapping[str, Any]], |
420 | 422 | batch_size: int = 1000, |
421 | 423 | primary_key: Optional[str] = None, |
422 | 424 | ) -> List[TaskInfo]: |
@@ -573,7 +575,7 @@ def add_documents_raw( |
573 | 575 | return TaskInfo(**response) |
574 | 576 |
|
575 | 577 | def update_documents( |
576 | | - self, documents: List[Dict[str, Any]], primary_key: Optional[str] = None |
| 578 | + self, documents: Sequence[Mapping[str, Any]], primary_key: Optional[str] = None |
577 | 579 | ) -> TaskInfo: |
578 | 580 | """Update documents in the index. |
579 | 581 |
|
@@ -721,7 +723,7 @@ def update_documents_raw( |
721 | 723 |
|
722 | 724 | def update_documents_in_batches( |
723 | 725 | self, |
724 | | - documents: List[Dict[str, Any]], |
| 726 | + documents: Sequence[Mapping[str, Any]], |
725 | 727 | batch_size: int = 1000, |
726 | 728 | primary_key: Optional[str] = None, |
727 | 729 | ) -> List[TaskInfo]: |
@@ -865,7 +867,7 @@ def get_settings(self) -> Dict[str, Any]: |
865 | 867 | """ |
866 | 868 | return self.http.get(f"{self.config.paths.index}/{self.uid}/{self.config.paths.setting}") |
867 | 869 |
|
868 | | - def update_settings(self, body: Dict[str, Any]) -> TaskInfo: |
| 870 | + def update_settings(self, body: Mapping[str, Any]) -> TaskInfo: |
869 | 871 | """Update settings of the index. |
870 | 872 |
|
871 | 873 | https://www.meilisearch.com/docs/reference/api/settings#update-settings |
@@ -1413,7 +1415,7 @@ def get_typo_tolerance(self) -> TypoTolerance: |
1413 | 1415 |
|
1414 | 1416 | return TypoTolerance(**typo_tolerance) |
1415 | 1417 |
|
1416 | | - def update_typo_tolerance(self, body: Union[Dict[str, Any], None]) -> TaskInfo: |
| 1418 | + def update_typo_tolerance(self, body: Union[Mapping[str, Any], None]) -> TaskInfo: |
1417 | 1419 | """Update typo tolerance of the index. |
1418 | 1420 |
|
1419 | 1421 | Parameters |
@@ -1535,7 +1537,7 @@ def get_faceting_settings(self) -> Faceting: |
1535 | 1537 |
|
1536 | 1538 | return Faceting(**faceting) |
1537 | 1539 |
|
1538 | | - def update_faceting_settings(self, body: Union[Dict[str, Any], None]) -> TaskInfo: |
| 1540 | + def update_faceting_settings(self, body: Union[Mapping[str, Any], None]) -> TaskInfo: |
1539 | 1541 | """Update the faceting settings of the index. |
1540 | 1542 |
|
1541 | 1543 | Parameters |
@@ -1757,8 +1759,8 @@ def reset_non_separator_tokens(self) -> TaskInfo: |
1757 | 1759 |
|
1758 | 1760 | @staticmethod |
1759 | 1761 | def _batch( |
1760 | | - documents: List[Dict[str, Any]], batch_size: int |
1761 | | - ) -> Generator[List[Dict[str, Any]], None, None]: |
| 1762 | + documents: Sequence[Mapping[str, Any]], batch_size: int |
| 1763 | + ) -> Generator[Sequence[Mapping[str, Any]], None, None]: |
1762 | 1764 | total_len = len(documents) |
1763 | 1765 | for i in range(0, total_len, batch_size): |
1764 | 1766 | yield documents[i : i + batch_size] |
|
0 commit comments