Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions django-stubs/db/models/enums.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class _IntegerChoicesType(ChoicesType):
# 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: ...
def __new__(cls, value: ConvertibleToInt) -> IntegerChoices: ...
@overload
def __init__(self, x: ConvertibleToInt, label: _StrOrPromise) -> None: ...
def __new__(cls, value: ConvertibleToInt, label: _StrOrPromise) -> IntegerChoices: ...
@enum_property
@override
def value(self) -> int: ...
Expand All @@ -80,9 +80,9 @@ class _TextChoicesType(ChoicesType):

class TextChoices(Choices, StrEnum, metaclass=_TextChoicesType): # type: ignore[misc]
@overload
def __init__(self, object: str) -> None: ...
def __new__(cls, value: str) -> TextChoices: ...
@overload
def __init__(self, object: str, label: _StrOrPromise) -> None: ...
def __new__(cls, value: str, label: _StrOrPromise) -> TextChoices: ...
@enum_property
@override
def value(self) -> str: ...
Expand Down
15 changes: 15 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ django.contrib.auth.views.UserModel
# Limited stubtest support for enums (https://github.com/python/mypy/issues/16806)
django.db.migrations.operations.base.OperationCategory.__new__

# The `label` parameter in __new__ is a deliberate stub-only addition:
# Django's ChoicesType metaclass processes (value, label) tuples at class definition time,
# but the runtime __new__ (from enum.Enum) only accepts (cls, value).
# We keep the label overload so that defining enum members type-checks correctly.
django.db.models.enums.IntegerChoices.__new__

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have absolutely no clue if any of that is correct. Do you have any ideas @ngnpope ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I'll have time to look into it this week

django.db.models.enums.TextChoices.__new__
django.db.models.IntegerChoices.__new__
django.db.models.TextChoices.__new__
django.contrib.gis.db.models.IntegerChoices.__new__
django.contrib.gis.db.models.TextChoices.__new__
django.tasks.TaskResultStatus.__new__
django.tasks.base.TaskResultStatus.__new__
django.tasks.base.TextChoices.__new__
django.tasks.signals.TaskResultStatus.__new__

# These are dynamically added when using `save(commit=False)`
# See https://docs.djangoproject.com/en/stable/topics/forms/modelforms/#the-save-method
django.forms.BaseModelForm.save_m2m
Expand Down
Loading