From 3ca4a905abd1b181b5a7c3ae43fada76f3fff23a Mon Sep 17 00:00:00 2001 From: SaJH Date: Sun, 27 Oct 2024 13:02:15 +0900 Subject: [PATCH 1/2] Update django.contrib.admin.models.LogEntryManager Signed-off-by: SaJH --- django-stubs/contrib/admin/models.pyi | 10 ++++++++++ scripts/stubtest/allowlist_todo_django51.txt | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/django-stubs/contrib/admin/models.pyi b/django-stubs/contrib/admin/models.pyi index a1ac77b49..3915e02a7 100644 --- a/django-stubs/contrib/admin/models.pyi +++ b/django-stubs/contrib/admin/models.pyi @@ -2,6 +2,7 @@ from typing import Any, ClassVar from uuid import UUID from django.db import models +from django.db.models import QuerySet from django.db.models.base import Model ADDITION: int @@ -19,6 +20,15 @@ class LogEntryManager(models.Manager[LogEntry]): action_flag: int, change_message: Any = ..., ) -> LogEntry: ... + def log_actions( + self, + user_id: int, + queryset: QuerySet[Model], + action_flag: int, + change_message: str | list[Any] = "", + *, + single_object: bool = False, + ) -> LogEntry | list[LogEntry]: ... class LogEntry(models.Model): action_time: models.DateTimeField diff --git a/scripts/stubtest/allowlist_todo_django51.txt b/scripts/stubtest/allowlist_todo_django51.txt index 306f38c52..4a9261c42 100644 --- a/scripts/stubtest/allowlist_todo_django51.txt +++ b/scripts/stubtest/allowlist_todo_django51.txt @@ -6,7 +6,6 @@ django.contrib.admin.ModelAdmin.log_deletions django.contrib.admin.helpers.Fieldset.is_collapsible django.contrib.admin.helpers.InlineAdminFormSet.is_collapsible -django.contrib.admin.models.LogEntryManager.log_actions django.contrib.admin.options.ModelAdmin.log_deletions django.contrib.auth.base_user.BaseUserManager.make_random_password django.contrib.auth.checks.check_middleware From 4f51b9505249bea6a46218a09b4c887228ee667b Mon Sep 17 00:00:00 2001 From: SaJH Date: Sat, 7 Dec 2024 15:50:27 +0900 Subject: [PATCH 2/2] Add overload decorator for log_actions to clarify return types Signed-off-by: SaJH --- django-stubs/contrib/admin/models.pyi | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/django-stubs/contrib/admin/models.pyi b/django-stubs/contrib/admin/models.pyi index a3fd44a66..f2fb0d520 100644 --- a/django-stubs/contrib/admin/models.pyi +++ b/django-stubs/contrib/admin/models.pyi @@ -1,4 +1,4 @@ -from typing import Any, ClassVar +from typing import Any, ClassVar, Literal, overload from uuid import UUID from django.db import models @@ -22,6 +22,7 @@ class LogEntryManager(models.Manager[LogEntry]): action_flag: int, change_message: Any = ..., ) -> LogEntry: ... + @overload def log_actions( self, user_id: int, @@ -29,8 +30,18 @@ class LogEntryManager(models.Manager[LogEntry]): action_flag: int, change_message: str | list[Any] = "", *, - single_object: bool = False, - ) -> LogEntry | list[LogEntry]: ... + single_object: Literal[True], + ) -> LogEntry: ... + @overload + def log_actions( + self, + user_id: int, + queryset: QuerySet[Model], + action_flag: int, + change_message: str | list[Any] = "", + *, + single_object: Literal[False] = False, + ) -> list[LogEntry]: ... class LogEntry(models.Model): action_time: models.DateTimeField