Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signature of Choices member creation, add assert_type test cases, run pyright #2162

Merged
merged 10 commits into from
May 24, 2024
16 changes: 12 additions & 4 deletions django-stubs/db/models/enums.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import enum
import sys
from typing import Any, TypeVar, type_check_only
from typing import Any, TypeVar, overload, type_check_only

from typing_extensions import Self, TypeAlias
from _typeshed import ConvertibleToInt
from django.utils.functional import _StrOrPromise
from typing_extensions import TypeAlias

_Self = TypeVar("_Self")

Expand Down Expand Up @@ -56,7 +58,10 @@ class _IntegerChoicesMeta(ChoicesType):
def values(self) -> list[int]: ...

class IntegerChoices(Choices, IntEnum, metaclass=_IntegerChoicesMeta):
def __new__(cls, value: int) -> Self: ...
@overload
def __init__(self, x: ConvertibleToInt) -> None: ...
@overload
def __init__(self, x: ConvertibleToInt, label: _StrOrPromise) -> None: ...
@_enum_property
def value(self) -> int: ...

Expand All @@ -69,6 +74,9 @@ class _TextChoicesMeta(ChoicesType):
def values(self) -> list[str]: ...

class TextChoices(Choices, StrEnum, metaclass=_TextChoicesMeta):
def __new__(cls, value: str | tuple[str, str]) -> Self: ...
@overload
def __init__(self, object: str) -> None: ...
@overload
def __init__(self, object: str, label: _StrOrPromise) -> None: ...
@_enum_property
def value(self) -> str: ...
Loading