Skip to content

Commit

Permalink
Annotate return value of all "deconstruct" methods
Browse files Browse the repository at this point in the history
This is typically some number of bool and string values, followed by the
*args and **kwargs of the object being deconstructed.

"BaseManager.deconstruct" has an even more complicated signature, where most
return elements can also be None.

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).
  • Loading branch information
brianhelba committed Sep 7, 2023
1 parent f9f1099 commit 972101c
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion django-stubs/db/models/constraints.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/expressions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/indexes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/manager.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 | None, str | None, Sequence[Any] | None, dict[str, Any] | None]: ...
def check(self, **kwargs: Any) -> list[Any]: ...
@classmethod
def from_queryset(cls, queryset_class: type[QuerySet[_T]], class_name: str | None = ...) -> type[Self]: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/query_utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 972101c

Please sign in to comment.