Description
in meilisearch/tasks.py we create root level functions. This is the only file in this project where we do not do object-oriented programming.
For example, we call get_task
in the get_task
method
meilisearch-python/meilisearch/client.py
Lines 402 to 423 in ebfb0bb
This leads to:
- Possible hard to understand code, where does the
get_task
come from? Is it an infinite loop? - Providing to the function the already initialized parameters of the Client class
- An inconsistency in pattern with the rest of the code
Suggestion:
Create a TaskHandler
class in meilisearch/task.py
that initializes the necessary information in its instance:
class TaskHandler():
def __init__(self, url: str, api_key: str | None = None, timeout: int | None = None) -> None:
"""
Parameters
----------
url:
The url to the Meilisearch API (ex: http://localhost:7700)
api_key:
The optional API key for Meilisearch
"""
self.config = Config(url, api_key, timeout=timeout)
self.http = HttpRequests(self.config)
add get_task
and get_tasks
as a method of this class. Remove the required Config
parameter.
import the TaskHandler
in the client file.
from meilisearch.task import TaskHandler
in the client method get_task
, call the function the following way:
def get_tasks(
self, parameters: dict[str, Any] | None = None
) -> dict[str, list[dict[str, Any]]]:
return self.taskHandler.get_task(uid)
Another solution would be to make all these functions static, in which way they would keep their current function prototype, there would be no need for an initialized and it will be called like this:
return TaskHandler.get_task(client, uid)
What do you think about this @sanders41 ?