Skip to content

Commit 2f587cb

Browse files
bors[bot]sanders41
andauthored
Merge #676
676: Update the return type of methods r=alallema a=sanders41 # Pull Request ## Related issue Fixes #610 Potentially fixes #449 ## What does this PR do? - Updates the return types for methods - Some of the methods listed in the issue don't return `TaskInfo` but I went ahead and updated them anyways because they are part of #449 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Paul Sanders <[email protected]>
2 parents 419b50c + b786736 commit 2f587cb

24 files changed

+391
-333
lines changed

meilisearch/client.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from meilisearch.config import Config
1414
from meilisearch.errors import MeiliSearchError
1515
from meilisearch.index import Index
16+
from meilisearch.models.key import Key, KeysResults
1617
from meilisearch.models.task import TaskInfo
1718
from meilisearch.task import cancel_tasks, delete_tasks, get_task, get_tasks, wait_for_task
1819

@@ -40,7 +41,7 @@ def __init__(
4041

4142
self.http = HttpRequests(self.config)
4243

43-
def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
44+
def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> TaskInfo:
4445
"""Create an index.
4546
4647
Parameters
@@ -52,8 +53,8 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Di
5253
5354
Returns
5455
-------
55-
task:
56-
Dictionary containing a task to track the informations about the progress of an asynchronous process.
56+
task_info:
57+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
5758
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
5859
5960
Raises
@@ -63,7 +64,7 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Di
6364
"""
6465
return Index.create(self.config, uid, options)
6566

66-
def delete_index(self, uid: str) -> Dict[str, Any]:
67+
def delete_index(self, uid: str) -> TaskInfo:
6768
"""Deletes an index
6869
6970
Parameters
@@ -73,7 +74,7 @@ def delete_index(self, uid: str) -> Dict[str, Any]:
7374
7475
Returns
7576
-------
76-
task:
77+
task_info:
7778
Dictionary containing a task to track the informations about the progress of an asynchronous process.
7879
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
7980
@@ -83,7 +84,9 @@ def delete_index(self, uid: str) -> Dict[str, Any]:
8384
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
8485
"""
8586

86-
return self.http.delete(f"{self.config.paths.index}/{uid}")
87+
task = self.http.delete(f"{self.config.paths.index}/{uid}")
88+
89+
return TaskInfo(**task)
8790

8891
def get_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, List[Index]]:
8992
"""Get all indexes.
@@ -241,7 +244,7 @@ def is_healthy(self) -> bool:
241244
return False
242245
return True
243246

244-
def get_key(self, key_or_uid: str) -> Dict[str, Any]:
247+
def get_key(self, key_or_uid: str) -> Key:
245248
"""Gets information about a specific API key.
246249
247250
Parameters
@@ -260,9 +263,11 @@ def get_key(self, key_or_uid: str) -> Dict[str, Any]:
260263
MeiliSearchApiError
261264
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
262265
"""
263-
return self.http.get(f"{self.config.paths.keys}/{key_or_uid}")
266+
key = self.http.get(f"{self.config.paths.keys}/{key_or_uid}")
267+
268+
return Key(**key)
264269

265-
def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
270+
def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> KeysResults:
266271
"""Gets the Meilisearch API keys.
267272
268273
Parameters
@@ -273,7 +278,7 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any
273278
Returns
274279
-------
275280
keys:
276-
Dictionary with limit, offset, total and results a list of dictionaries containing the key information.
281+
API keys.
277282
https://docs.meilisearch.com/reference/api/keys.html#get-keys
278283
279284
Raises
@@ -283,9 +288,11 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any
283288
"""
284289
if parameters is None:
285290
parameters = {}
286-
return self.http.get(f"{self.config.paths.keys}?{parse.urlencode(parameters)}")
291+
keys = self.http.get(f"{self.config.paths.keys}?{parse.urlencode(parameters)}")
287292

288-
def create_key(self, options: Dict[str, Any]) -> Dict[str, Any]:
293+
return KeysResults(**keys)
294+
295+
def create_key(self, options: Dict[str, Any]) -> Key:
289296
"""Creates a new API key.
290297
291298
Parameters
@@ -299,7 +306,7 @@ def create_key(self, options: Dict[str, Any]) -> Dict[str, Any]:
299306
300307
Returns
301308
-------
302-
keys:
309+
key:
303310
The new API key.
304311
https://docs.meilisearch.com/reference/api/keys.html#get-keys
305312
@@ -308,9 +315,11 @@ def create_key(self, options: Dict[str, Any]) -> Dict[str, Any]:
308315
MeiliSearchApiError
309316
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
310317
"""
311-
return self.http.post(f"{self.config.paths.keys}", options)
318+
task = self.http.post(f"{self.config.paths.keys}", options)
319+
320+
return Key(**task)
312321

313-
def update_key(self, key_or_uid: str, options: Dict[str, Any]) -> Dict[str, Any]:
322+
def update_key(self, key_or_uid: str, options: Dict[str, Any]) -> Key:
314323
"""Update an API key.
315324
316325
Parameters
@@ -333,9 +342,11 @@ def update_key(self, key_or_uid: str, options: Dict[str, Any]) -> Dict[str, Any]
333342
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
334343
"""
335344
url = f"{self.config.paths.keys}/{key_or_uid}"
336-
return self.http.patch(url, options)
345+
key = self.http.patch(url, options)
337346

338-
def delete_key(self, key_or_uid: str) -> Dict[str, int]:
347+
return Key(**key)
348+
349+
def delete_key(self, key_or_uid: str) -> int:
339350
"""Deletes an API key.
340351
341352
Parameters
@@ -354,7 +365,9 @@ def delete_key(self, key_or_uid: str) -> Dict[str, int]:
354365
MeiliSearchApiError
355366
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
356367
"""
357-
return self.http.delete(f"{self.config.paths.keys}/{key_or_uid}")
368+
response = self.http.delete(f"{self.config.paths.keys}/{key_or_uid}")
369+
370+
return response.status_code
358371

359372
def get_version(self) -> Dict[str, str]:
360373
"""Get version Meilisearch
@@ -386,7 +399,7 @@ def version(self) -> Dict[str, str]:
386399
"""
387400
return self.get_version()
388401

389-
def create_dump(self) -> Dict[str, str]:
402+
def create_dump(self) -> TaskInfo:
390403
"""Trigger the creation of a Meilisearch dump.
391404
392405
Returns
@@ -400,7 +413,9 @@ def create_dump(self) -> Dict[str, str]:
400413
MeiliSearchApiError
401414
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
402415
"""
403-
return self.http.post(self.config.paths.dumps)
416+
task = self.http.post(self.config.paths.dumps)
417+
418+
return TaskInfo(**task)
404419

405420
def swap_indexes(self, parameters: List[Dict[str, List[str]]]) -> TaskInfo:
406421
"""Swap two indexes.

0 commit comments

Comments
 (0)