From ef4aaa2ad6d5ddb35165e1cea7882a39e28bc855 Mon Sep 17 00:00:00 2001 From: Noelle Leigh <5957867+noelleleigh@users.noreply.github.com> Date: Wed, 1 May 2024 14:23:28 -0400 Subject: [PATCH] django.utils.deconstruct: Improve types Adds generic type hints to `@deconstructible` 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]]: ...