From fa9ee69885213770c42342a8f1f6f182308b13ee Mon Sep 17 00:00:00 2001 From: Noelle Leigh <5957867+noelleleigh@users.noreply.github.com> Date: Sat, 4 May 2024 17:52:05 -0400 Subject: [PATCH] `django.utils.deconstruct`: Improve types (#238) Adds generic type hints to [`@deconstructible`](https://docs.djangoproject.com/en/4.2/topics/migrations/#adding-a-deconstruct-method) so that it preserves the implicit types of the class it decorates. I don't know of a way to indicate that the class it returns has a `decorator()` method attached to it. --- django-stubs/utils/deconstruct.pyi | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/django-stubs/utils/deconstruct.pyi b/django-stubs/utils/deconstruct.pyi index 51f1b3678..67853a661 100644 --- a/django-stubs/utils/deconstruct.pyi +++ b/django-stubs/utils/deconstruct.pyi @@ -1,3 +1,11 @@ -from typing import Any +from collections.abc import Callable +from typing import Any, TypeVar, overload -def deconstructible(*args: Any, path: Any | None = ...) -> Any: ... +T = TypeVar("T") + +@overload +def deconstructible(klass: type[T]) -> type[T]: ... +@overload +def deconstructible( + *args: Any, path: str | None = ... +) -> Callable[[type[T]], type[T]]: ...