From 6fa69e6983de7f8678c1131bc27b1dce7a619950 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Thu, 7 Sep 2023 17:36:24 -0400 Subject: [PATCH] Annotate return value of all "deconstruct" methods This is typically some number of bool and string values, followed by the *args and **kwargs of the object being deconstructed. Use "Sequence" as the type of *args, because multiple places in Django actually return this as a list (even though Python always treats *args as a tuple). --- django-stubs/db/models/constraints.pyi | 2 +- django-stubs/db/models/expressions.pyi | 2 +- django-stubs/db/models/fields/__init__.pyi | 2 +- django-stubs/db/models/indexes.pyi | 2 +- django-stubs/db/models/manager.pyi | 2 +- django-stubs/db/models/query_utils.pyi | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/django-stubs/db/models/constraints.pyi b/django-stubs/db/models/constraints.pyi index 07c580c217..ccef885d4d 100644 --- a/django-stubs/db/models/constraints.pyi +++ b/django-stubs/db/models/constraints.pyi @@ -21,7 +21,7 @@ class BaseConstraint: def constraint_sql(self, model: type[Model] | None, schema_editor: BaseDatabaseSchemaEditor | None) -> str: ... def create_sql(self, model: type[Model] | None, schema_editor: BaseDatabaseSchemaEditor | None) -> str: ... def remove_sql(self, model: type[Model] | None, schema_editor: BaseDatabaseSchemaEditor | None) -> str: ... - def deconstruct(self) -> Any: ... + def deconstruct(self) -> tuple[str, Sequence[Any], dict[str, Any]]: ... def clone(self) -> Self: ... class CheckConstraint(BaseConstraint): diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index f9d7ed3631..9703acad67 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -107,7 +107,7 @@ class BaseExpression: def reverse_ordering(self) -> BaseExpression: ... def flatten(self) -> Iterator[BaseExpression]: ... def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... - def deconstruct(self) -> Any: ... # fake + def deconstruct(self) -> tuple[str, Sequence[Any], dict[str, Any]]: ... # fake class Expression(BaseExpression, Combinable): ... diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 877ee412ab..0943d041c9 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -190,7 +190,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): # non-Model instances @overload def __get__(self, instance: Any, owner: Any) -> Self: ... - def deconstruct(self) -> Any: ... + def deconstruct(self) -> tuple[str, str, Sequence[Any], dict[str, Any]]: ... def set_attributes_from_name(self, name: str) -> None: ... def db_type_parameters(self, connection: BaseDatabaseWrapper) -> DictWrapper: ... def db_check(self, connection: BaseDatabaseWrapper) -> str | None: ... diff --git a/django-stubs/db/models/indexes.pyi b/django-stubs/db/models/indexes.pyi index fe370f0dff..9041eb6ede 100644 --- a/django-stubs/db/models/indexes.pyi +++ b/django-stubs/db/models/indexes.pyi @@ -37,7 +37,7 @@ class Index: self, model: type[Model], schema_editor: BaseDatabaseSchemaEditor, using: str = ..., **kwargs: Any ) -> Statement: ... def remove_sql(self, model: type[Model], schema_editor: BaseDatabaseSchemaEditor, **kwargs: Any) -> str: ... - def deconstruct(self) -> Any: ... + def deconstruct(self) -> tuple[str, Sequence[Any], dict[str, Any]]: ... def clone(self) -> Index: ... def set_name_with_model(self, model: type[Model]) -> None: ... diff --git a/django-stubs/db/models/manager.pyi b/django-stubs/db/models/manager.pyi index d74df80a88..7cef1a61de 100644 --- a/django-stubs/db/models/manager.pyi +++ b/django-stubs/db/models/manager.pyi @@ -21,7 +21,7 @@ class BaseManager(Generic[_T]): def __init__(self) -> None: ... def deconstruct( self, - ) -> tuple[bool, str | None, str | None, tuple[Any, ...] | None, dict[str, Any] | None]: ... + ) -> tuple[bool, str, str, Sequence[Any], dict[str, Any]]: ... def check(self, **kwargs: Any) -> list[Any]: ... @classmethod def from_queryset(cls, queryset_class: type[QuerySet[_T]], class_name: str | None = ...) -> type[Self]: ... diff --git a/django-stubs/db/models/query_utils.pyi b/django-stubs/db/models/query_utils.pyi index 0333a0f540..313e2a1a27 100644 --- a/django-stubs/db/models/query_utils.pyi +++ b/django-stubs/db/models/query_utils.pyi @@ -40,7 +40,7 @@ class Q(tree.Node): summarize: bool = ..., for_save: bool = ..., ) -> WhereNode: ... - def deconstruct(self) -> tuple[str, tuple, dict[str, str]]: ... + def deconstruct(self) -> tuple[str, Sequence[Any], dict[str, Any]]: ... class DeferredAttribute: field: Field