Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add more precise typing #449

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

Closed
bidoubiwa opened this issue Apr 25, 2022 · 3 comments · Fixed by #676
Closed

Add more precise typing #449

bidoubiwa opened this issue Apr 25, 2022 · 3 comments · Fixed by #676
Labels
enhancement New feature or request

Comments

@bidoubiwa
Copy link
Contributor

See this thread for context:

To enjoy the advantages of types, we should consider adding more complex types to this repo.

As per the thread

@brunoocasali asking if it is breaking.
answer from @sanders41

@brunoocasali it depends on how you look at it. Really Dict[str, int] has been wrong since tasks were introduced and I am thinking @alallema is first to notice and made the correction here. So really it was breaking in a previous release and a bug fix here.

The reason this was easy to miss is a dictionary is returned, but mypy has no way to know what the dictionary will be with the current implementation. Since all it knows you you said you are returning a dictionary and one is being returned it assumes you have the rest correct. The point @bidoubiwa brings up would prevent this from happening because at that point mypy would know exactly what to expect in the return values.

Implementation:

from @sanders41

There is a TypedDict, but it is first available in Python 3.8. You can do it all the way back to Python 3.6 by using Pydantic classes instead of dictionaries, but that would be a big change.

Pydantic is how I do it so if you do decide to go this direction feel free to grab my models and use them here https://github.com/sanders41/meilisearch-python-async/tree/main/meilisearch_python_async/models

@bidoubiwa bidoubiwa added the enhancement New feature or request label Apr 25, 2022
@sanders41
Copy link
Collaborator

@alallema if you want help or have questions with this let me know. Also, since this will be a breaking change it would be a good time to also drop Python 3.6 support, info here #378.

@brunoocasali
Copy link
Member

The idea is to drop just the 3.6 and support the minimum non-eol version which is 3.7 right?

@sanders41
Copy link
Collaborator

The idea is to drop just the 3.6 and support the minimum non-eol version which is 3.7 right?

Correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants