meilisearch-python icon indicating copy to clipboard operation
meilisearch-python copied to clipboard

Add more precise typing

Open bidoubiwa opened this issue 3 years ago • 3 comments

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 avatar Apr 25 '22 19:04 bidoubiwa

@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.

sanders41 avatar Apr 26 '22 13:04 sanders41

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

brunoocasali avatar Apr 26 '22 20:04 brunoocasali

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

Correct

sanders41 avatar Apr 26 '22 20:04 sanders41