Skip to content

Commit

Permalink
cleanup some stubs in contrib.admin, contrib.admindocs (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov authored Sep 17, 2019
1 parent 813dd8c commit a8fdd4c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 55 deletions.
6 changes: 4 additions & 2 deletions django-stubs/contrib/admin/decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Callable, Optional
from typing import Any, Callable, Optional, Type

def register(*models: Any, site: Optional[Any] = ...) -> Callable: ...
from django.db.models.base import Model

def register(*models: Type[Model], site: Optional[Any] = ...) -> Callable: ...
8 changes: 4 additions & 4 deletions django-stubs/contrib/admin/helpers.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, Iterable

from django.contrib.auth.forms import AdminPasswordChangeForm
from django.forms.boundfield import BoundField
Expand Down Expand Up @@ -26,7 +26,7 @@ class AdminForm:
form: AdminPasswordChangeForm,
fieldsets: List[Tuple[None, Dict[str, List[str]]]],
prepopulated_fields: Dict[Any, Any],
readonly_fields: Any = ...,
readonly_fields: Optional[Iterable[Any]] = ...,
model_admin: Any = ...,
) -> None: ...
def __iter__(self) -> Iterator[Fieldset]: ...
Expand All @@ -47,7 +47,7 @@ class Fieldset:
self,
form: Any,
name: Optional[Any] = ...,
readonly_fields: Any = ...,
readonly_fields: Optional[Iterable[Any]] = ...,
fields: Any = ...,
classes: Any = ...,
description: Optional[Any] = ...,
Expand All @@ -64,7 +64,7 @@ class Fieldline:
model_admin: Any = ...
readonly_fields: Any = ...
def __init__(
self, form: Any, field: Any, readonly_fields: Optional[Any] = ..., model_admin: Optional[Any] = ...
self, form: Any, field: Any, readonly_fields: Optional[Iterable[Any]] = ..., model_admin: Optional[Any] = ...
) -> None: ...
def __iter__(self) -> Iterator[Union[AdminField, AdminReadonlyField]]: ...
def errors(self) -> SafeText: ...
Expand Down
3 changes: 0 additions & 3 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class BaseModelAdmin:
show_full_result_count: bool = ...
checks_class: Any = ...
def check(self, **kwargs: Any) -> List[Union[str, Error]]: ...
def __init__(self) -> None: ...
def formfield_for_dbfield(
self, db_field: Field, request: Optional[HttpRequest], **kwargs: Any
) -> Optional[Field]: ...
Expand Down Expand Up @@ -94,7 +93,6 @@ class BaseModelAdmin:
def has_module_permission(self, request: HttpRequest) -> bool: ...

class ModelAdmin(BaseModelAdmin):
formfield_overrides: Any
list_display: Sequence[Union[str, Callable]] = ...
list_display_links: Optional[Sequence[Union[str, Callable]]] = ...
list_filter: Sequence[Union[str, Type[ListFilter], Tuple[str, Type[ListFilter]]]] = ...
Expand Down Expand Up @@ -122,7 +120,6 @@ class ModelAdmin(BaseModelAdmin):
actions_on_top: bool = ...
actions_on_bottom: bool = ...
actions_selection_counter: bool = ...
checks_class: Any = ...
model: Type[Model] = ...
opts: Options = ...
admin_site: AdminSite = ...
Expand Down
8 changes: 4 additions & 4 deletions django-stubs/contrib/admin/sites.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union

from django.contrib.admin.options import ModelAdmin
from django.core.handlers.wsgi import WSGIRequest
from django.db.models.base import Model
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
from django.urls.resolvers import URLPattern, URLResolver
from django.urls.resolvers import URLResolver
from django.utils.functional import LazyObject

all_sites: Any
Expand All @@ -31,11 +31,11 @@ class AdminSite:
def check(self, app_configs: None) -> List[Any]: ...
def register(
self,
model_or_iterable: Union[List[Type[Model]], Tuple[Type[Model]], Type[Model]],
model_or_iterable: Union[Type[Model], Iterable[Type[Model]]],
admin_class: Optional[Type[ModelAdmin]] = ...,
**options: Any
) -> None: ...
def unregister(self, model_or_iterable: Type[Model]) -> None: ...
def unregister(self, model_or_iterable: Union[Type[Model], Iterable[Type[Model]]]) -> None: ...
def is_registered(self, model: Type[Model]) -> bool: ...
def add_action(self, action: Callable, name: None = ...) -> None: ...
def disable_action(self, name: str) -> None: ...
Expand Down
10 changes: 6 additions & 4 deletions django-stubs/contrib/admin/views/decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any, Callable, Optional
from typing import Callable, TypeVar, overload

def staff_member_required(
view_func: Optional[Callable] = ..., redirect_field_name: str = ..., login_url: str = ...
) -> Callable: ...
_C = TypeVar("_C", bound=Callable)
@overload
def staff_member_required(view_func: _C = ..., redirect_field_name: str = ..., login_url: str = ...) -> _C: ...
@overload
def staff_member_required(view_func: None = ..., redirect_field_name: str = ..., login_url: str = ...) -> Callable: ...
47 changes: 9 additions & 38 deletions django-stubs/contrib/admindocs/views.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,17 @@ from typing import Any, Optional, Union
from django.db.models.fields import Field
from django.views.generic import TemplateView

from .utils import get_view_name

MODEL_METHODS_EXCLUDE: Any

class BaseAdminDocsView(TemplateView):
template_name: str = ...
def dispatch(self, request: Any, *args: Any, **kwargs: Any): ...
def get_context_data(self, **kwargs: Any): ...

class BookmarkletsView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...

class TemplateTagIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...

class TemplateFilterIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...

class ViewIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...

class ViewDetailView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...

class ModelIndexView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...

class ModelDetailView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...

class TemplateDetailView(BaseAdminDocsView):
template_name: str = ...
def get_context_data(self, **kwargs: Any): ...
class BaseAdminDocsView(TemplateView): ...
class BookmarkletsView(BaseAdminDocsView): ...
class TemplateTagIndexView(BaseAdminDocsView): ...
class TemplateFilterIndexView(BaseAdminDocsView): ...
class ViewIndexView(BaseAdminDocsView): ...
class ViewDetailView(BaseAdminDocsView): ...
class ModelIndexView(BaseAdminDocsView): ...
class ModelDetailView(BaseAdminDocsView): ...
class TemplateDetailView(BaseAdminDocsView): ...

def get_return_data_type(func_name: Any): ...
def get_readable_field_data_type(field: Union[Field, str]) -> str: ...
Expand Down

0 comments on commit a8fdd4c

Please sign in to comment.