Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions django-stubs/db/models/enums.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ from _typeshed import ConvertibleToInt
from django.utils.functional import _StrOrPromise
from typing_extensions import deprecated

from django_stubs_ext.compat import MYPY

if sys.version_info >= (3, 11):
from enum import EnumType, IntEnum, StrEnum
from enum import property as enum_property
Expand Down Expand Up @@ -59,10 +61,12 @@ class _IntegerChoicesType(ChoicesType):
# all the arguments of `int.__new__`/`str.__new__` (e.g. `base`, `encoding`).
# They are omitted on purpose to avoid having convoluted stubs for these enums:
class IntegerChoices(Choices, IntEnum, metaclass=_IntegerChoicesType): # type: ignore[misc]
@overload
def __init__(self, x: ConvertibleToInt) -> None: ...
@overload
def __init__(self, x: ConvertibleToInt, label: _StrOrPromise) -> None: ...
if not MYPY: # noqa: PYI002
@overload
def __init__(self, x: ConvertibleToInt) -> None: ...
@overload
def __init__(self, x: ConvertibleToInt, label: _StrOrPromise) -> None: ...

@enum_property
def value(self) -> int: ...

Expand All @@ -75,10 +79,12 @@ class _TextChoicesType(ChoicesType):
def values(self) -> list[str]: ...

class TextChoices(Choices, StrEnum, metaclass=_TextChoicesType): # type: ignore[misc]
@overload
def __init__(self, object: str) -> None: ...
@overload
def __init__(self, object: str, label: _StrOrPromise) -> None: ...
if not MYPY: # noqa: PYI002
@overload
def __init__(self, object: str) -> None: ...
@overload
def __init__(self, object: str, label: _StrOrPromise) -> None: ...

@enum_property
def value(self) -> str: ...

Expand Down
4 changes: 4 additions & 0 deletions ext/django_stubs_ext/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Literal

# Magic constant that mypy overrides to True during type checking
MYPY: Literal[False]
Loading