Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow Any generics #1339

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
31ef26e
Fix admin action return type
christianbundy Jan 22, 2023
c089372
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 22, 2023
3fe1a91
Use HttpResponseBase to support StreamingHttpResponse
christianbundy Jan 23, 2023
5bc0daa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 23, 2023
a71a424
Fix usage
christianbundy Jan 23, 2023
50ed1fe
Merge branch 'master' of github.com:typeddjango/django-stubs into chr…
christianbundy Jan 23, 2023
aa9dea3
Fix issues
christianbundy Jan 23, 2023
92da2c1
Fix test
christianbundy Jan 23, 2023
d004b1b
Remove redundant comma
christianbundy Jan 23, 2023
3fa57f0
Use `T | None` rather than `Optional[T]`
christianbundy Jan 23, 2023
66e29c9
Add freestanding actions to test
christianbundy Jan 23, 2023
0477a26
Add negative test cases
christianbundy Jan 23, 2023
ea49719
Add unhappier paths and fix problems
christianbundy Jan 23, 2023
0494aa5
Fix Field
christianbundy Jan 24, 2023
72e4d76
Fix tuple
christianbundy Jan 24, 2023
52931f9
Fix accidental changes
christianbundy Jan 24, 2023
67bcbf6
Fix dict
christianbundy Jan 24, 2023
12efe41
Fix QuerySet
christianbundy Jan 24, 2023
1d3b00a
Fix ModelForm
christianbundy Jan 24, 2023
17fbf7c
Fix PostgresOperatorLookup
christianbundy Jan 24, 2023
2f19735
Fix File
christianbundy Jan 24, 2023
38f91fe
Fix Manager
christianbundy Jan 24, 2023
be19241
Fix ForeignKey
christianbundy Jan 24, 2023
16db657
Fix CharField
christianbundy Jan 24, 2023
4c7f506
Fix Lookup
christianbundy Jan 24, 2023
faa7885
Fix UploadedFile
christianbundy Jan 24, 2023
99dc74d
Fix IntegerField
christianbundy Jan 24, 2023
851f5fa
Fix _DisplayT
christianbundy Jan 24, 2023
f1a5850
Fix Paginator
christianbundy Jan 24, 2023
02d878a
Fix BooleanField
christianbundy Jan 24, 2023
f7cc279
Fix fields
christianbundy Jan 24, 2023
bbee01e
Fix BaseModelAdmin
christianbundy Jan 24, 2023
9f682c7
Fix Sitemap
christianbundy Jan 24, 2023
3e1e1ab
Fix MultiValueDict
christianbundy Jan 24, 2023
838c66d
Fix the rest of the errors
christianbundy Jan 24, 2023
d6aba2e
Fix TypeAlias import
christianbundy Jan 24, 2023
9bcb79d
HACK: Make mypy-test.ini to avoid changing tests
christianbundy Jan 24, 2023
cf35f4b
Merge branch 'master' of github.com:typeddjango/django-stubs into chr…
christianbundy Jan 24, 2023
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
4 changes: 2 additions & 2 deletions django-stubs/apps/registry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Apps:
apps_ready: bool
ready_event: threading.Event
loading: bool
_pending_operations: dict[tuple[str, str], list]
_pending_operations: dict[tuple[str, str], list[Any]]
models_ready: bool
ready: bool
def __init__(self, installed_apps: Iterable[AppConfig | str] | None = ...) -> None: ...
Expand All @@ -35,7 +35,7 @@ class Apps:
def set_installed_apps(self, installed: Iterable[str]) -> None: ...
def unset_installed_apps(self) -> None: ...
def clear_cache(self) -> None: ...
def lazy_model_operation(self, function: Callable, *model_keys: Any) -> None: ...
def lazy_model_operation(self, function: Callable[..., Any], *model_keys: Any) -> None: ...
def do_pending_operations(self, model: type[Model]) -> None: ...

apps: Apps
2 changes: 1 addition & 1 deletion django-stubs/conf/urls/static.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ from typing import Any

from django.urls.resolvers import URLPattern

def static(prefix: str, view: Callable = ..., **kwargs: Any) -> list[URLPattern]: ...
def static(prefix: str, view: Callable[..., Any] = ..., **kwargs: Any) -> list[URLPattern]: ...
5 changes: 4 additions & 1 deletion django-stubs/contrib/admin/actions.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.contrib.admin.options import ModelAdmin
from django.db.models import Model
from django.db.models.query import QuerySet
from django.http.request import HttpRequest
from django.template.response import TemplateResponse

def delete_selected(modeladmin: ModelAdmin, request: HttpRequest, queryset: QuerySet) -> TemplateResponse | None: ...
def delete_selected(
modeladmin: ModelAdmin[Model], request: HttpRequest, queryset: QuerySet[Model]
) -> TemplateResponse | None: ...
5 changes: 3 additions & 2 deletions django-stubs/contrib/admin/checks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ from typing import Any
from django.apps.config import AppConfig
from django.contrib.admin.options import BaseModelAdmin
from django.core.checks.messages import CheckMessage, Error
from django.db.models import Model

def check_admin_app(app_configs: Sequence[AppConfig] | None, **kwargs: Any) -> list[CheckMessage]: ...
def check_dependencies(**kwargs: Any) -> list[CheckMessage]: ...

class BaseModelAdminChecks:
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ...
def check(self, admin_obj: BaseModelAdmin[Model], **kwargs: Any) -> list[CheckMessage]: ...

class ModelAdminChecks(BaseModelAdminChecks):
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ...
def check(self, admin_obj: BaseModelAdmin[Model], **kwargs: Any) -> list[CheckMessage]: ...

class InlineModelAdminChecks(BaseModelAdminChecks):
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... # type: ignore
Expand Down
16 changes: 9 additions & 7 deletions django-stubs/contrib/admin/decorators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ from django.contrib.admin.sites import AdminSite
from django.db.models import Combinable, QuerySet
from django.db.models.base import Model
from django.db.models.expressions import BaseExpression
from django.http import HttpRequest
from django.http import HttpRequest, HttpResponseBase
from django.utils.functional import _StrOrPromise
from typing_extensions import TypeAlias

_Model = TypeVar("_Model", bound=Model)
_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin)
_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[Model])
_Request = TypeVar("_Request", bound=HttpRequest)
_QuerySet = TypeVar("_QuerySet", bound=QuerySet)
_QuerySet = TypeVar("_QuerySet", bound=QuerySet[Model])
# This is deliberately different from _DisplayT defined in contrib.admin.options
_DisplayCallable: TypeAlias = Union[Callable[[_ModelAdmin, _Model], Any], Callable[[_Model], Any]] # noqa: Y037
_DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable)
_DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable[ModelAdmin[Model], Model])
_ActionReturn = TypeVar("_ActionReturn", bound=HttpResponseBase | None)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this currently builds off of my other branch, #1331.


@overload
def action(
function: Callable[[_ModelAdmin, _Request, _QuerySet], None],
function: Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn],
permissions: Sequence[str] | None = ...,
description: _StrOrPromise | None = ...,
) -> Callable[[_ModelAdmin, _Request, _QuerySet], None]: ...
) -> Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]: ...
@overload
def action(
*,
permissions: Sequence[str] | None = ...,
description: _StrOrPromise | None = ...,
) -> Callable[
[Callable[[_ModelAdmin, _Request, _QuerySet], None]], Callable[[_ModelAdmin, _Request, _QuerySet], None]
[Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]],
Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn],
]: ...
@overload
def display(
Expand Down
24 changes: 13 additions & 11 deletions django-stubs/contrib/admin/filters.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,45 @@ class ListFilter:
template: str
used_parameters: Any
def __init__(
self, request: HttpRequest, params: dict[str, str], model: type[Model], model_admin: ModelAdmin
self, request: HttpRequest, params: dict[str, str], model: type[Model], model_admin: ModelAdmin[Model]
) -> None: ...
def has_output(self) -> bool: ...
def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ...
def queryset(self, request: HttpRequest, queryset: QuerySet) -> QuerySet | None: ...
def queryset(self, request: HttpRequest, queryset: QuerySet[Model]) -> QuerySet[Model] | None: ...
def expected_parameters(self) -> list[str] | None: ...

class SimpleListFilter(ListFilter):
parameter_name: str | None
lookup_choices: Any
def value(self) -> str | None: ...
def lookups(self, request: HttpRequest, model_admin: ModelAdmin) -> Iterable[tuple[Any, str]] | None: ...
def lookups(self, request: HttpRequest, model_admin: ModelAdmin[Model]) -> Iterable[tuple[Any, str]] | None: ...
def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ...

class FieldListFilter(ListFilter):
field: Field
field: Field[Any, Any]
field_path: str
title: str
def __init__(
self,
field: Field,
field: Field[Any, Any],
request: HttpRequest,
params: dict[str, str],
model: type[Model],
model_admin: ModelAdmin,
model_admin: ModelAdmin[Model],
field_path: str,
) -> None: ...
@classmethod
def register(cls, test: Callable, list_filter_class: type[FieldListFilter], take_priority: bool = ...) -> None: ...
def register(
cls, test: Callable[..., Any], list_filter_class: type[FieldListFilter], take_priority: bool = ...
) -> None: ...
@classmethod
def create(
cls,
field: Field,
field: Field[Any, Any],
request: HttpRequest,
params: dict[str, str],
model: type[Model],
model_admin: ModelAdmin,
model_admin: ModelAdmin[Model],
field_path: str,
) -> FieldListFilter: ...

Expand All @@ -67,7 +69,7 @@ class RelatedFieldListFilter(FieldListFilter):
@property
def include_empty_choice(self) -> bool: ...
def field_choices(
self, field: RelatedField, request: HttpRequest, model_admin: ModelAdmin
self, field: RelatedField[Any, Any], request: HttpRequest, model_admin: ModelAdmin[Model]
) -> list[tuple[str, str]]: ...
def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ...

Expand Down Expand Up @@ -104,7 +106,7 @@ class AllValuesFieldListFilter(FieldListFilter):
lookup_val: Any
lookup_val_isnull: Any
empty_value_display: str
lookup_choices: QuerySet
lookup_choices: QuerySet[Model]
def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ...

class RelatedOnlyFieldListFilter(RelatedFieldListFilter):
Expand Down
46 changes: 23 additions & 23 deletions django-stubs/contrib/admin/helpers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ class _PrepopulatedDict(TypedDict):

class AdminForm:
prepopulated_fields: list[_PrepopulatedDict]
model_admin: ModelAdmin | None
model_admin: ModelAdmin[Model] | None
readonly_fields: Sequence[str]
form: ModelForm
form: ModelForm[Model]
fieldsets: list[tuple[Any, dict[str, list[str]]]]
def __init__(
self,
form: ModelForm,
form: ModelForm[Model],
fieldsets: list[tuple[Any, dict[str, list[str]]]],
prepopulated_fields: Mapping[str, Iterable[str]],
readonly_fields: Sequence[str] | None = ...,
model_admin: ModelAdmin | None = ...,
model_admin: ModelAdmin[Model] | None = ...,
) -> None: ...
def __iter__(self) -> Iterator[Fieldset]: ...
@property
Expand All @@ -48,37 +48,37 @@ class AdminForm:
def media(self) -> Media: ...

class Fieldset:
form: ModelForm
form: ModelForm[Model]
classes: str
description: str | None
model_admin: ModelAdmin | None
model_admin: ModelAdmin[Model] | None
readonly_fields: Sequence[str]
def __init__(
self,
form: ModelForm,
form: ModelForm[Model],
name: Any | None = ...,
readonly_fields: Sequence[str] = ...,
fields: Sequence[str] = ...,
classes: Iterable[str] = ...,
description: str | None = ...,
model_admin: ModelAdmin | None = ...,
model_admin: ModelAdmin[Model] | None = ...,
) -> None: ...
@property
def media(self) -> Media: ...
def __iter__(self) -> Iterator[Fieldline]: ...

class Fieldline:
form: ModelForm
form: ModelForm[Model]
fields: Sequence[str]
has_visible_field: bool
model_admin: ModelAdmin | None
model_admin: ModelAdmin[Model] | None
readonly_fields: Sequence[str]
def __init__(
self,
form: ModelForm,
form: ModelForm[Model],
field: str | Sequence[str],
readonly_fields: Sequence[str] | None = ...,
model_admin: ModelAdmin | None = ...,
model_admin: ModelAdmin[Model] | None = ...,
) -> None: ...
def __iter__(self) -> Iterator[AdminField | AdminReadonlyField]: ...
def errors(self) -> SafeString: ...
Expand All @@ -88,7 +88,7 @@ class AdminField:
is_first: bool
is_checkbox: bool
is_readonly: bool
def __init__(self, form: ModelForm, field: str, is_first: bool) -> None: ...
def __init__(self, form: ModelForm[Model], field: str, is_first: bool) -> None: ...
def label_tag(self) -> SafeString: ...
def errors(self) -> SafeString: ...

Expand All @@ -100,18 +100,18 @@ class _FieldDictT(TypedDict):

class AdminReadonlyField:
field: _FieldDictT
form: ModelForm
model_admin: ModelAdmin | None
form: ModelForm[Model]
model_admin: ModelAdmin[Model] | None
is_first: bool
is_checkbox: bool
is_readonly: bool
empty_value_display: Any
def __init__(
self,
form: ModelForm,
form: ModelForm[Model],
field: Callable[[Model], Any] | str,
is_first: bool,
model_admin: ModelAdmin | None = ...,
model_admin: ModelAdmin[Model] | None = ...,
) -> None: ...
def label_tag(self) -> SafeString: ...
def contents(self) -> SafeString: ...
Expand All @@ -120,7 +120,7 @@ class InlineAdminFormSet:
opts: Any
formset: Any
fieldsets: Any
model_admin: ModelAdmin | None
model_admin: ModelAdmin[Model] | None
readonly_fields: Sequence[str]
prepopulated_fields: dict[str, Any]
classes: str
Expand All @@ -135,7 +135,7 @@ class InlineAdminFormSet:
fieldsets: Any,
prepopulated_fields: dict[str, Any] | None = ...,
readonly_fields: Sequence[str] | None = ...,
model_admin: ModelAdmin | None = ...,
model_admin: ModelAdmin[Model] | None = ...,
has_add_permission: bool = ...,
has_change_permission: bool = ...,
has_delete_permission: bool = ...,
Expand All @@ -159,16 +159,16 @@ class InlineAdminForm(AdminForm):
def __init__(
self,
formset: Any,
form: ModelForm,
form: ModelForm[Model],
fieldsets: Any,
prepopulated_fields: Any,
original: bool | None,
readonly_fields: Sequence[str] | None = ...,
model_admin: ModelAdmin | None = ...,
model_admin: ModelAdmin[Model] | None = ...,
view_on_site_url: str | None = ...,
) -> None: ...
def __iter__(self) -> Iterator[InlineFieldset]: ...
def needs_explicit_pk_field(self) -> bool | AutoField: ...
def needs_explicit_pk_field(self) -> bool | AutoField[Any, Any]: ...
def pk_field(self) -> AdminField: ...
def fk_field(self) -> AdminField: ...
def deletion_field(self) -> AdminField: ...
Expand All @@ -179,4 +179,4 @@ class InlineFieldset(Fieldset):
def __iter__(self) -> Iterator[Fieldline]: ...

class AdminErrorList(forms.utils.ErrorList):
def __init__(self, form: ModelForm, inline_formsets: Any) -> None: ...
def __init__(self, form: ModelForm[Model], inline_formsets: Any) -> None: ...
14 changes: 7 additions & 7 deletions django-stubs/contrib/admin/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class LogEntryManager(models.Manager[LogEntry]):
) -> LogEntry: ...

class LogEntry(models.Model):
action_time: models.DateTimeField
user: models.ForeignKey
content_type: models.ForeignKey
object_id: models.TextField
object_repr: models.CharField
action_flag: models.PositiveSmallIntegerField
change_message: models.TextField
action_time: models.DateTimeField[Any, Any]
user: models.ForeignKey[Any, Any]
content_type: models.ForeignKey[Any, Any]
object_id: models.TextField[Any, Any]
object_repr: models.CharField[Any, Any]
action_flag: models.PositiveSmallIntegerField[Any, Any]
change_message: models.TextField[Any, Any]
objects: LogEntryManager
def is_addition(self) -> bool: ...
def is_change(self) -> bool: ...
Expand Down
Loading