Skip to content

Commit

Permalink
django.utils.deconstruct: Improve types (#238)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
noelleleigh authored May 4, 2024
1 parent e10857e commit fa9ee69
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions django-stubs/utils/deconstruct.pyi
Original file line number Diff line number Diff line change
@@ -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]]: ...

0 comments on commit fa9ee69

Please sign in to comment.