Skip to content

Improve typing of string enums #2567

Open

Description

@pquentin

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 #1691 which is about using Python classes for enums.

Activity

  1. changed the title [-]Improve typing of enums[/-] [+]Improve typing of string enums[/+] on May 24, 2024
  2. self-assigned this
    on Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions