From 978379c45478d8c77299c97cd23cdaa27f47b512 Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Tue, 29 Jan 2019 20:29:19 +0300 Subject: [PATCH] add stubs for admin_changeset tests --- django-stubs/contrib/admin/options.pyi | 26 +++++++++---------- django-stubs/contrib/admin/sites.pyi | 1 + .../contrib/admin/templatetags/admin_list.pyi | 4 +-- django-stubs/contrib/admin/views/main.pyi | 2 ++ django-stubs/db/models/expressions.pyi | 2 ++ django-stubs/db/models/functions/__init__.pyi | 2 +- django-stubs/db/models/query_utils.pyi | 2 ++ scripts/typecheck_tests.py | 6 ++++- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index adf5282..16bd3ab 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -1,5 +1,5 @@ from collections import OrderedDict -from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union +from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union, Sequence from django.contrib.admin.filters import SimpleListFilter from django.contrib.admin.models import LogEntry @@ -94,13 +94,13 @@ class BaseModelAdmin: class ModelAdmin(BaseModelAdmin): formfield_overrides: Any - list_display: Any = ... - list_display_links: Any = ... - list_filter: Any = ... - list_select_related: bool = ... + list_display: Sequence[str] = ... + list_display_links: Sequence[str] = ... + list_filter: Sequence[str] = ... + list_select_related: Sequence[str] = ... list_per_page: int = ... list_max_show_all: int = ... - list_editable: Any = ... + list_editable: Sequence[str] = ... search_fields: Any = ... date_hierarchy: Any = ... save_as: bool = ... @@ -167,17 +167,17 @@ class ModelAdmin(BaseModelAdmin): self, request: WSGIRequest, default_choices: List[Tuple[str, str]] = ... ) -> List[Tuple[str, str]]: ... def get_action(self, action: Union[Callable, str]) -> Tuple[Callable, str, str]: ... - def get_list_display(self, request: WSGIRequest) -> Union[List[Callable], List[str], Tuple[str]]: ... - def get_list_display_links( - self, request: WSGIRequest, list_display: Union[List[Callable], List[str], Tuple[str]] - ) -> Optional[Union[List[Callable], List[str], Tuple[str]]]: ... - def get_list_filter(self, request: WSGIRequest) -> Union[List[Type[SimpleListFilter]], List[str], Tuple]: ... - def get_list_select_related(self, request: WSGIRequest) -> Union[Tuple, bool]: ... - def get_search_fields(self, request: WSGIRequest) -> Union[List[str], Tuple]: ... + def get_list_display(self, request: WSGIRequest) -> Sequence[str]: ... + def get_list_display_links(self, request: WSGIRequest, list_display: Sequence[str]) -> Optional[Sequence[str]]: ... + def get_list_filter(self, request: WSGIRequest) -> Sequence[str]: ... + def get_list_select_related(self, request: WSGIRequest) -> Sequence[str]: ... + def get_search_fields(self, request: WSGIRequest) -> List[str]: ... def get_search_results( self, request: WSGIRequest, queryset: QuerySet, search_term: str ) -> Tuple[QuerySet, bool]: ... def get_preserved_filters(self, request: WSGIRequest) -> str: ... + def _get_edited_object_pks(self, request: WSGIRequest, prefix: str) -> List[str]: ... + def _get_list_editable_queryset(self, request: WSGIRequest, prefix: str) -> QuerySet: ... def construct_change_message( self, request: WSGIRequest, form: AdminPasswordChangeForm, formsets: None, add: bool = ... ) -> List[Dict[str, Dict[str, List[str]]]]: ... diff --git a/django-stubs/contrib/admin/sites.pyi b/django-stubs/contrib/admin/sites.pyi index 1ed42c6..fc9e450 100644 --- a/django-stubs/contrib/admin/sites.pyi +++ b/django-stubs/contrib/admin/sites.pyi @@ -26,6 +26,7 @@ class AdminSite: password_change_template: Any = ... password_change_done_template: Any = ... name: str = ... + _registry: Dict[Type[Model], ModelAdmin] def __init__(self, name: str = ...) -> None: ... def check(self, app_configs: None) -> List[str]: ... def register( diff --git a/django-stubs/contrib/admin/templatetags/admin_list.pyi b/django-stubs/contrib/admin/templatetags/admin_list.pyi index 94e4381..2b7f2bb 100644 --- a/django-stubs/contrib/admin/templatetags/admin_list.pyi +++ b/django-stubs/contrib/admin/templatetags/admin_list.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, Iterator, List, Optional, Union +from typing import Any, Dict, Iterator, List, Optional, Union, Iterable from django.contrib.admin.filters import FieldListFilter from django.contrib.admin.templatetags.base import InclusionAdminNode @@ -15,7 +15,7 @@ register: Any DOT: str def paginator_number(cl: ChangeList, i: int) -> SafeText: ... -def pagination(cl: ChangeList) -> Dict[str, Union[List[Union[int, str]], ChangeList, int, range, str]]: ... +def pagination(cl: ChangeList) -> Dict[str, Iterable[Any]]: ... def pagination_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... def result_headers(cl: ChangeList) -> Iterator[Dict[str, Optional[Union[int, str]]]]: ... def items_for_result(cl: ChangeList, result: Model, form: None) -> Iterator[SafeText]: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index e934108..7acc4a7 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -9,6 +9,7 @@ from django.db.models.expressions import Combinable, CombinedExpression, OrderBy from django.db.models.query import QuerySet from django.db.models.options import Options +from django.forms.formsets import BaseFormSet ALL_VAR: str ORDER_VAR: str @@ -44,6 +45,7 @@ class ChangeList: queryset: Any = ... title: Any = ... pk_attname: Any = ... + formset: Optional[BaseFormSet] def __init__( self, request: WSGIRequest, diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index a93d073..04d18c5 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -111,6 +111,8 @@ class F(Combinable): summarize: bool = ..., for_save: bool = ..., ) -> Expression: ... + def asc(self, **kwargs) -> OrderBy: ... + def desc(self, **kwargs) -> OrderBy: ... class OuterRef(F): ... diff --git a/django-stubs/db/models/functions/__init__.pyi b/django-stubs/db/models/functions/__init__.pyi index cfe95f0..88f42c8 100644 --- a/django-stubs/db/models/functions/__init__.pyi +++ b/django-stubs/db/models/functions/__init__.pyi @@ -1 +1 @@ -from .text import Lower as Lower +from .text import Lower as Lower, Upper as Upper diff --git a/django-stubs/db/models/query_utils.pyi b/django-stubs/db/models/query_utils.pyi index 95f749f..c31331f 100644 --- a/django-stubs/db/models/query_utils.pyi +++ b/django-stubs/db/models/query_utils.pyi @@ -58,6 +58,8 @@ class RegisterLookupMixin: def merge_dicts(dicts: List[Dict[str, Any]]) -> Dict[str, Any]: ... @classmethod def register_lookup(cls, lookup: Any, lookup_name: Optional[str] = ...) -> Type[Any]: ... + @classmethod + def _unregister_lookup(cls, lookup: Any, lookup_name: Optional[str] = ...): ... def select_related_descend( field: Field, diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index e224cf1..065c5d8 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -21,12 +21,16 @@ IGNORED_ERROR_PATTERNS = [ 'Cannot infer type of lambda', 'Incompatible types in assignment (expression has type "Callable[', 'Invalid value for a to= parameter', + 'Incompatible types in assignment (expression has type "FilteredChildAdmin", variable has type "ChildAdmin")', re.compile(r'"Callable\[\[(Any(, )?)+\], Any\]" has no attribute'), re.compile(r'"HttpResponseBase" has no attribute "[A-Za-z_]+"'), + re.compile(r'Incompatible types in assignment \(expression has type "Tuple\[\]", ' + r'variable has type "Tuple\[[A-Za-z, ]+\]"'), ] TESTS_DIRS = [ 'absolute_url_overrides', - 'admin_autodiscover' + 'admin_autodiscover', + 'admin_changelist', ]