You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The enum functional API is too dynamic for static type checking. In this case mypy would need to know how to split "A B C" and determine the types of each. Even as a list -- ["A", "B", "C"] -- it would need to iterate over that list.
Under the hood this will effectively look like an enum with no members to mypy and, as such, none of the other stuff built on top of that will work properly. (IIRC it's because mypy's enum plugin just gives up and bails out early.)
If you want to have type checking with enums/choicse, use the non-functional approach to defining enums.
See #729 (comment) for a previous response related to this.
@intgr I think it'd be worth adding a section to the FAQ to discourage use of the functional API as it seems as though it's not something that will ever be fixable.
Similar to #1858 (comment), even if we can't teach mypy to understand the dynamically generated members of enum classes, I believe we can fix still typechecking of the constructor arguments?
Bug report
What's wrong
The stubs package does not support the functional enum API for choice enums.
How is that should be
Enum classes like
TextChoices
support the functional enum API (4th code block in that section).System information
python
version: 3.10.12django
version: 4.2.8mypy
version: 1.7.1django-stubs
version: 4.2.7django-stubs-ext
version: 4.2.7Repro
The text was updated successfully, but these errors were encountered: