elastic / elasticsearch-py

Official Python client for Elasticsearch
https://ela.st/es-python
Apache License 2.0
4.17k stars 1.17k forks source link

Improve typing of string enums #2567

Open pquentin opened 1 month ago

pquentin commented 1 month ago

Today, string enums are typed using Literal to allow specific values and None if the value is not set, which is OK. However, we also use str as an option, which allows any value and defeats the purpose of having types in the first place.

For example, see wait_for in https://elasticsearch-py.readthedocs.io/en/v8.13.1/api/ml.html#elasticsearch.client.MlClient.start_trained_model_deployment. The type is Literal['fully_allocated', 'started', 'starting'] | str | None which prevents any useful type checking. We should remove the str type.

Note that this is different from https://github.com/elastic/elasticsearch-py/issues/1691 which is about using Python classes for enums.