From 574a87e68cfb2e6ff66b3d7e1a0bb75f51148a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne?= Date: Mon, 22 Jun 2020 01:08:09 -0700 Subject: [PATCH] explicitly mark value and label types on choices enum (#406) 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 --- django-stubs/db/models/enums.pyi | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/django-stubs/db/models/enums.pyi b/django-stubs/db/models/enums.pyi index ddfe548..557312e 100644 --- a/django-stubs/db/models/enums.pyi +++ b/django-stubs/db/models/enums.pyi @@ -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): @@ -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): @@ -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: ...