Skip to content

Adding type hints and mypy #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 4, 2021
Merged

Adding type hints and mypy #267

merged 5 commits into from
Jun 4, 2021

Conversation

sanders41
Copy link
Collaborator

Closes #264

Unfortunately the methods in the HttpRequests class can return so may different types, I was up to Union[dict[str, Any], List[Dict[str, Any]], List[str], List[int], str, requests.Response] and not done, that I had to go with Any which mean mypy wasn't able to check the return types from calls to methods in that class. Since those are the values that are usually returned from methods in the Client and Index classes that means mypy wasn't able to check those values. Luckily that class is only supposed to be used internally so code editors and users of the package will still get the benefits from the type hints and mypy. Developers of this package also still get the same benefits.

@curquiza
Copy link
Member

curquiza commented Jun 2, 2021

Hello @sanders41, thanks a lot for your PR :)
We'll take a look as soon as possible!

@sanders41
Copy link
Collaborator Author

No problem, no hurry on my end. Sorry it's a big one I couldn't think of a good way to split it up.

@curquiza curquiza requested a review from alallema June 3, 2021 10:33
"""Get all indexes in dictionary format.

Returns
-------
indexes: list
indexes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some colons are missing sometimes

return self.http.delete(f'{self.config.paths.index}/{self.uid}')

def update(self, **body):
def update(self, **body: Dict[str, Any]) -> "Index":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we exchange "Index" for 'Index'? It seems to me that it's better for string literals.

@@ -70,14 +78,9 @@ def update(self, **body):
self.updated_at = self._iso_to_date_time(response['updatedAt'])
return self

def fetch_info(self):
def fetch_info(self) -> "Index":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also "Index" to 'Index'

@@ -1,20 +1,29 @@
import json
from typing import Any, Callable, Dict, List, Optional, Union

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

import requests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

"""Create the index.

Parameters
----------
uid: str
uid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uid
uid:

UID of the index.
options: dict, optional
options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options
options:

time interval the method should wait (sleep) between requests

Returns
-------
update: dict
update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
update
update:

"""Get all indexes in dictionary format.

Returns
-------
indexes: list
indexes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
indexes
indexes:

Comment on lines +54 to +68
mypy:
name: mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install pipenv
uses: dschep/install-pipenv-action@v1
- name: Install dependencies
run: pipenv install --dev
- name: mypy type check
run: pipenv run mypy meilisearch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR @sanders41!

Can you add the mypy check to bors too?

@curquiza
Copy link
Member

curquiza commented Jun 3, 2021

Hi @sanders41! I've just given you write access to this repo if you agree! It will avoid you to fork this project for the next contributions 🙂 Also, your reviews on PR will be taken into account by GitHub!
Thanks for your involvement, we really appreciate working with you 😁

@sanders41
Copy link
Collaborator Author

@alallema these updates are done

@curquiza thanks, sounds good to me!

Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @sanders41!

@alallema
Copy link
Contributor

alallema commented Jun 4, 2021

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 4, 2021

@bors bors bot merged commit defc5b8 into meilisearch:main Jun 4, 2021
@sanders41 sanders41 deleted the mypy branch June 4, 2021 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type Hints and MyPy
3 participants