Skip to content

Commit

Permalink
explicitly mark value and label types on choices enum (typeddjango#406)
Browse files Browse the repository at this point in the history
In addition to the meta properties added
to the Choices enums, value and label are
set for each choice.
This commit explicitly types those instead of the
tuple value and non-extant label types
  • Loading branch information
ehossack authored Jun 22, 2020
1 parent 82ae175 commit 574a87e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions django-stubs/db/models/enums.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class ChoicesMeta(enum.EnumMeta):

class Choices(enum.Enum, metaclass=ChoicesMeta):
def __str__(self): ...
@property
def label(self) -> str: ...
@property
def value(self) -> Any: ...

# fake
class _IntegerChoicesMeta(ChoicesMeta):
Expand All @@ -18,7 +22,9 @@ class _IntegerChoicesMeta(ChoicesMeta):
labels: List[str] = ...
values: List[int] = ...

class IntegerChoices(int, Choices, metaclass=_IntegerChoicesMeta): ...
class IntegerChoices(int, Choices, metaclass=_IntegerChoicesMeta):
@property
def value(self) -> int: ...

# fake
class _TextChoicesMeta(ChoicesMeta):
Expand All @@ -27,4 +33,6 @@ class _TextChoicesMeta(ChoicesMeta):
labels: List[str] = ...
values: List[str] = ...

class TextChoices(str, Choices, metaclass=_TextChoicesMeta): ...
class TextChoices(str, Choices, metaclass=_TextChoicesMeta):
@property
def value(self) -> str: ...

0 comments on commit 574a87e

Please sign in to comment.