Skip to content

Commit bb705d9

Browse files
authored
Annotate return type of reverse_lazy() (#2766)
Update `urls.base.pyi` with an annotated `_StrPromise` return type for `reverse_lazy()` Fixes ##2765
1 parent 1f2b728 commit bb705d9

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

django-stubs/urls/base.pyi

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,36 @@ from typing import Any, Literal, TypeAlias
44
from django.http.request import QueryDict
55
from django.http.response import HttpResponseBase
66
from django.urls.resolvers import ResolverMatch
7+
from django.utils.functional import _StrPromise
78

89
# https://github.com/python/typeshed/blob/87f599dc8312ac67b941b5f2b47274534a1a2d3a/stdlib/urllib/parse.pyi#L136-L138
910
_QueryType: TypeAlias = (
1011
Mapping[Any, Any] | Mapping[Any, Sequence[Any]] | Sequence[tuple[Any, Any]] | Sequence[tuple[Any, Sequence[Any]]]
1112
)
1213

1314
def resolve(path: str, urlconf: str | None = ...) -> ResolverMatch: ...
15+
16+
# NOTE: make sure `reverse` and `reverse_lazy` objects are in sync:
1417
def reverse(
1518
viewname: Callable[..., HttpResponseBase] | str | None,
16-
urlconf: str | None = ...,
17-
args: Sequence[Any] | None = ...,
18-
kwargs: dict[str, Any] | None = ...,
19-
current_app: str | None = ...,
19+
urlconf: str | None = None,
20+
args: Sequence[Any] | None = None,
21+
kwargs: dict[str, Any] | None = None,
22+
current_app: str | None = None,
2023
*,
21-
query: QueryDict | _QueryType | None = ...,
22-
fragment: str | None = ...,
24+
query: QueryDict | _QueryType | None = None,
25+
fragment: str | None = None,
2326
) -> str: ...
24-
25-
reverse_lazy: Any
26-
27+
def reverse_lazy(
28+
viewname: Callable[..., HttpResponseBase] | str | None,
29+
urlconf: str | None = None,
30+
args: Sequence[Any] | None = None,
31+
kwargs: dict[str, Any] | None = None,
32+
current_app: str | None = None,
33+
*,
34+
query: QueryDict | _QueryType | None = None,
35+
fragment: str | None = None,
36+
) -> _StrPromise: ...
2737
def clear_url_caches() -> None: ...
2838
def set_script_prefix(prefix: str) -> None: ...
2939
def get_script_prefix() -> str: ...

0 commit comments

Comments
 (0)