Skip to content

Commit 7e02f44

Browse files
committed
Add new _ListDisplayT type alias
This renames `_DisplayT` to `_ListDisplayT` and creates a new `_DisplayT` alias with the contents of the `_ListOrTuple`. This will be used in the next commit.
1 parent 34f93f1 commit 7e02f44

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

django-stubs/contrib/admin/options.pyi

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ _ListFilterT: TypeAlias = (
8282
# Generic type specifically for models, for use in BaseModelAdmin and subclasses
8383
# https://github.com/typeddjango/django-stubs/issues/482
8484
_ModelT = TypeVar("_ModelT", bound=Model)
85-
_DisplayT: TypeAlias = _ListOrTuple[str | Callable[[_ModelT], str | bool]]
85+
_DisplayT: TypeAlias = str | Callable[[_ModelT], str | bool]
86+
_ListDisplayT: TypeAlias = _ListOrTuple[_DisplayT[_ModelT]]
8687

8788
# Options `form`, `list_display`, `list_display_links` and `actions` are not marked as `ClassVar` due to the
8889
# limitations of the current type system: `ClassVar` cannot contain type variables.
@@ -130,7 +131,7 @@ class BaseModelAdmin(Generic[_ModelT]):
130131
def get_readonly_fields(self, request: HttpRequest, obj: _ModelT | None = ...) -> _ListOrTuple[str]: ...
131132
def get_prepopulated_fields(self, request: HttpRequest, obj: _ModelT | None = ...) -> dict[str, Sequence[str]]: ...
132133
def get_queryset(self, request: HttpRequest) -> QuerySet[_ModelT]: ...
133-
def get_sortable_by(self, request: HttpRequest) -> _DisplayT[_ModelT]: ...
134+
def get_sortable_by(self, request: HttpRequest) -> _ListDisplayT[_ModelT]: ...
134135
@overload
135136
@deprecated("None value for the request parameter will be removed in Django 6.0.")
136137
def lookup_allowed(self, lookup: str, value: str, request: None = None) -> bool: ...
@@ -150,8 +151,8 @@ _ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[Any])
150151
_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], HttpResponseBase | None]
151152

152153
class ModelAdmin(BaseModelAdmin[_ModelT]):
153-
list_display: _DisplayT[_ModelT]
154-
list_display_links: _DisplayT[_ModelT] | None
154+
list_display: _ListDisplayT[_ModelT]
155+
list_display_links: _ListDisplayT[_ModelT] | None
155156
list_filter: ClassVar[_ListOrTuple[_ListFilterT]]
156157
list_select_related: ClassVar[bool | _ListOrTuple[str]]
157158
list_per_page: ClassVar[int]
@@ -220,8 +221,10 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
220221
self, request: HttpRequest, default_choices: list[tuple[str, str]] = ...
221222
) -> list[tuple[str, str]]: ...
222223
def get_action(self, action: Callable | str) -> tuple[Callable[..., str], str, str] | None: ...
223-
def get_list_display(self, request: HttpRequest) -> _DisplayT[_ModelT]: ...
224-
def get_list_display_links(self, request: HttpRequest, list_display: _DisplayT[_ModelT]) -> _DisplayT[_ModelT]: ...
224+
def get_list_display(self, request: HttpRequest) -> _ListDisplayT[_ModelT]: ...
225+
def get_list_display_links(
226+
self, request: HttpRequest, list_display: _ListDisplayT[_ModelT]
227+
) -> _ListDisplayT[_ModelT]: ...
225228
def get_list_filter(self, request: HttpRequest) -> _ListOrTuple[_ListFilterT]: ...
226229
def get_list_select_related(self, request: HttpRequest) -> bool | _ListOrTuple[str]: ...
227230
def get_search_fields(self, request: HttpRequest) -> _ListOrTuple[str]: ...

django-stubs/contrib/admin/views/main.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from typing import Any, Literal
33

44
from django import forms
55
from django.contrib.admin.filters import ListFilter
6-
from django.contrib.admin.options import ModelAdmin, _DisplayT, _ListFilterT
6+
from django.contrib.admin.options import ModelAdmin, _ListDisplayT, _ListFilterT
77
from django.db.models.base import Model
88
from django.db.models.expressions import Expression
99
from django.db.models.options import Options
@@ -26,8 +26,8 @@ class ChangeList:
2626
opts: Options
2727
lookup_opts: Options
2828
root_queryset: QuerySet
29-
list_display: _DisplayT
30-
list_display_links: _DisplayT
29+
list_display: _ListDisplayT
30+
list_display_links: _ListDisplayT
3131
list_filter: Sequence[_ListFilterT]
3232
date_hierarchy: Any
3333
search_fields: Sequence[str]
@@ -58,8 +58,8 @@ class ChangeList:
5858
self,
5959
request: HttpRequest,
6060
model: type[Model],
61-
list_display: _DisplayT,
62-
list_display_links: _DisplayT,
61+
list_display: _ListDisplayT,
62+
list_display_links: _ListDisplayT,
6363
list_filter: Sequence[_ListFilterT],
6464
date_hierarchy: str | None,
6565
search_fields: Sequence[str],

0 commit comments

Comments
 (0)