Skip to content

Commit 6ea9351

Browse files
Fix TestClient.get regression (#2812)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 572a7cb commit 6ea9351

File tree

2 files changed

+57
-26
lines changed

2 files changed

+57
-26
lines changed

django-stubs/test/client.pyi

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ from django.http.response import HttpResponseBase
1818
from django.template.base import Template
1919
from django.test.utils import ContextList
2020
from django.urls import ResolverMatch
21-
from django.utils.functional import cached_property
21+
from django.utils.functional import _StrOrPromise, cached_property
2222

2323
BOUNDARY: str
2424
MULTIPART_CONTENT: str
@@ -88,7 +88,7 @@ class _RequestFactory(Generic[_T]):
8888
def request(self, **request: Any) -> _T: ...
8989
def get(
9090
self,
91-
path: str,
91+
path: _StrOrPromise,
9292
data: _GetDataType = ...,
9393
secure: bool = ...,
9494
*,
@@ -98,7 +98,7 @@ class _RequestFactory(Generic[_T]):
9898
) -> _T: ...
9999
def post(
100100
self,
101-
path: str,
101+
path: _StrOrPromise,
102102
data: Any = ...,
103103
content_type: str = ...,
104104
secure: bool = ...,
@@ -109,7 +109,7 @@ class _RequestFactory(Generic[_T]):
109109
) -> _T: ...
110110
def head(
111111
self,
112-
path: str,
112+
path: _StrOrPromise,
113113
data: Any = ...,
114114
secure: bool = ...,
115115
*,
@@ -119,7 +119,7 @@ class _RequestFactory(Generic[_T]):
119119
) -> _T: ...
120120
def trace(
121121
self,
122-
path: str,
122+
path: _StrOrPromise,
123123
secure: bool = ...,
124124
*,
125125
headers: Mapping[str, Any] | None = ...,
@@ -128,7 +128,7 @@ class _RequestFactory(Generic[_T]):
128128
) -> _T: ...
129129
def options(
130130
self,
131-
path: str,
131+
path: _StrOrPromise,
132132
data: dict[str, str] | str = ...,
133133
content_type: str = ...,
134134
secure: bool = ...,
@@ -139,7 +139,7 @@ class _RequestFactory(Generic[_T]):
139139
) -> _T: ...
140140
def put(
141141
self,
142-
path: str,
142+
path: _StrOrPromise,
143143
data: Any = ...,
144144
content_type: str = ...,
145145
secure: bool = ...,
@@ -150,7 +150,7 @@ class _RequestFactory(Generic[_T]):
150150
) -> _T: ...
151151
def patch(
152152
self,
153-
path: str,
153+
path: _StrOrPromise,
154154
data: Any = ...,
155155
content_type: str = ...,
156156
secure: bool = ...,
@@ -161,7 +161,7 @@ class _RequestFactory(Generic[_T]):
161161
) -> _T: ...
162162
def delete(
163163
self,
164-
path: str,
164+
path: _StrOrPromise,
165165
data: Any = ...,
166166
content_type: str = ...,
167167
secure: bool = ...,
@@ -173,7 +173,7 @@ class _RequestFactory(Generic[_T]):
173173
def generic(
174174
self,
175175
method: str,
176-
path: str,
176+
path: _StrOrPromise,
177177
data: Any = ...,
178178
content_type: str | None = ...,
179179
secure: bool = ...,
@@ -283,7 +283,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
283283
def request(self, **request: Any) -> _MonkeyPatchedWSGIResponse: ...
284284
def get( # type: ignore[override]
285285
self,
286-
path: str,
286+
path: _StrOrPromise,
287287
data: _GetDataType = ...,
288288
follow: bool = ...,
289289
secure: bool = ...,
@@ -294,7 +294,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
294294
) -> _MonkeyPatchedWSGIResponse: ...
295295
def post( # type: ignore[override]
296296
self,
297-
path: str,
297+
path: _StrOrPromise,
298298
data: Any = ...,
299299
content_type: str = ...,
300300
follow: bool = ...,
@@ -306,7 +306,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
306306
) -> _MonkeyPatchedWSGIResponse: ...
307307
def head( # type: ignore[override]
308308
self,
309-
path: str,
309+
path: _StrOrPromise,
310310
data: Any = ...,
311311
follow: bool = ...,
312312
secure: bool = ...,
@@ -317,7 +317,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
317317
) -> _MonkeyPatchedWSGIResponse: ...
318318
def options( # type: ignore[override]
319319
self,
320-
path: str,
320+
path: _StrOrPromise,
321321
data: dict[str, str] | str = ...,
322322
content_type: str = ...,
323323
follow: bool = ...,
@@ -329,7 +329,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
329329
) -> _MonkeyPatchedWSGIResponse: ...
330330
def put( # type: ignore[override]
331331
self,
332-
path: str,
332+
path: _StrOrPromise,
333333
data: Any = ...,
334334
content_type: str = ...,
335335
follow: bool = ...,
@@ -341,7 +341,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
341341
) -> _MonkeyPatchedWSGIResponse: ...
342342
def patch( # type: ignore[override]
343343
self,
344-
path: str,
344+
path: _StrOrPromise,
345345
data: Any = ...,
346346
content_type: str = ...,
347347
follow: bool = ...,
@@ -353,7 +353,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
353353
) -> _MonkeyPatchedWSGIResponse: ...
354354
def delete( # type: ignore[override]
355355
self,
356-
path: str,
356+
path: _StrOrPromise,
357357
data: Any = ...,
358358
content_type: str = ...,
359359
follow: bool = ...,
@@ -365,7 +365,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
365365
) -> _MonkeyPatchedWSGIResponse: ...
366366
def trace( # type: ignore[override]
367367
self,
368-
path: str,
368+
path: _StrOrPromise,
369369
data: Any = ...,
370370
follow: bool = ...,
371371
secure: bool = ...,
@@ -393,7 +393,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
393393
async def request(self, **request: Any) -> _MonkeyPatchedASGIResponse: ...
394394
async def get( # type: ignore[override]
395395
self,
396-
path: str,
396+
path: _StrOrPromise,
397397
data: _GetDataType = ...,
398398
follow: bool = ...,
399399
secure: bool = ...,
@@ -404,7 +404,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
404404
) -> _MonkeyPatchedASGIResponse: ...
405405
async def post( # type: ignore[override]
406406
self,
407-
path: str,
407+
path: _StrOrPromise,
408408
data: Any = ...,
409409
content_type: str = ...,
410410
follow: bool = ...,
@@ -416,7 +416,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
416416
) -> _MonkeyPatchedASGIResponse: ...
417417
async def head( # type: ignore[override]
418418
self,
419-
path: str,
419+
path: _StrOrPromise,
420420
data: Any = ...,
421421
follow: bool = ...,
422422
secure: bool = ...,
@@ -427,7 +427,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
427427
) -> _MonkeyPatchedASGIResponse: ...
428428
async def options( # type: ignore[override]
429429
self,
430-
path: str,
430+
path: _StrOrPromise,
431431
data: dict[str, str] | str = ...,
432432
content_type: str = ...,
433433
follow: bool = ...,
@@ -439,7 +439,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
439439
) -> _MonkeyPatchedASGIResponse: ...
440440
async def put( # type: ignore[override]
441441
self,
442-
path: str,
442+
path: _StrOrPromise,
443443
data: Any = ...,
444444
content_type: str = ...,
445445
follow: bool = ...,
@@ -451,7 +451,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
451451
) -> _MonkeyPatchedASGIResponse: ...
452452
async def patch( # type: ignore[override]
453453
self,
454-
path: str,
454+
path: _StrOrPromise,
455455
data: Any = ...,
456456
content_type: str = ...,
457457
follow: bool = ...,
@@ -463,7 +463,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
463463
) -> _MonkeyPatchedASGIResponse: ...
464464
async def delete( # type: ignore[override]
465465
self,
466-
path: str,
466+
path: _StrOrPromise,
467467
data: Any = ...,
468468
content_type: str = ...,
469469
follow: bool = ...,
@@ -475,7 +475,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
475475
) -> _MonkeyPatchedASGIResponse: ...
476476
async def trace( # type: ignore[override]
477477
self,
478-
path: str,
478+
path: _StrOrPromise,
479479
data: Any = ...,
480480
follow: bool = ...,
481481
secure: bool = ...,

tests/assert_type/test/client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from django.test import Client
2+
from django.urls import reverse, reverse_lazy
3+
4+
url_reverse = reverse("some:namespace")
5+
url_lazy = reverse_lazy("some:namespace")
6+
url_str = "/abc/def"
7+
8+
client = Client()
9+
client.get(url_reverse)
10+
client.get(url_lazy)
11+
client.get(url_str)
12+
13+
client.post(url_reverse)
14+
client.post(url_lazy)
15+
client.post(url_str)
16+
17+
client.patch(url_reverse)
18+
client.patch(url_lazy)
19+
client.patch(url_str)
20+
21+
client.put(url_reverse)
22+
client.put(url_lazy)
23+
client.put(url_str)
24+
25+
client.delete(url_reverse)
26+
client.delete(url_lazy)
27+
client.delete(url_str)
28+
29+
client.generic("GET", url_reverse)
30+
client.generic("POST", url_lazy)
31+
client.generic("DELETE", url_str)

0 commit comments

Comments
 (0)