Skip to content

Commit 7150dcd

Browse files
authored
Use Mapping instead of dict for test Client headers, add missing RequestFactory argument (#1537)
* Added missing headers= parameter to RequestFactory * Changed from dict[] to Mapping[], immutable ABCs are preferred for parameter types due to https://mypy.readthedocs.io/en/stable/common_issues.html#variance . This solves djangorestframework-stubs CI issue.
1 parent c75ada3 commit 7150dcd

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

django-stubs/test/client.pyi

+21-19
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ class _RequestFactory(Generic[_T]):
7070
defaults: dict[str, str]
7171
cookies: SimpleCookie
7272
errors: BytesIO
73-
def __init__(self, *, json_encoder: type[JSONEncoder] = ..., **defaults: Any) -> None: ...
73+
def __init__(
74+
self, *, json_encoder: type[JSONEncoder] = ..., headers: Mapping[str, Any] | None = ..., **defaults: Any
75+
) -> None: ...
7476
def request(self, **request: Any) -> _T: ...
7577
def get(
7678
self,
7779
path: str,
7880
data: _GetDataType = ...,
7981
secure: bool = ...,
8082
*,
81-
headers: dict[str, Any] | None = ...,
83+
headers: Mapping[str, Any] | None = ...,
8284
**extra: Any
8385
) -> _T: ...
8486
def post(
@@ -88,21 +90,21 @@ class _RequestFactory(Generic[_T]):
8890
content_type: str = ...,
8991
secure: bool = ...,
9092
*,
91-
headers: dict[str, Any] | None = ...,
93+
headers: Mapping[str, Any] | None = ...,
9294
**extra: Any
9395
) -> _T: ...
9496
def head(
95-
self, path: str, data: Any = ..., secure: bool = ..., *, headers: dict[str, Any] | None = ..., **extra: Any
97+
self, path: str, data: Any = ..., secure: bool = ..., *, headers: Mapping[str, Any] | None = ..., **extra: Any
9698
) -> _T: ...
97-
def trace(self, path: str, secure: bool = ..., *, headers: dict[str, Any] | None = ..., **extra: Any) -> _T: ...
99+
def trace(self, path: str, secure: bool = ..., *, headers: Mapping[str, Any] | None = ..., **extra: Any) -> _T: ...
98100
def options(
99101
self,
100102
path: str,
101103
data: dict[str, str] | str = ...,
102104
content_type: str = ...,
103105
secure: bool = ...,
104106
*,
105-
headers: dict[str, Any] | None = ...,
107+
headers: Mapping[str, Any] | None = ...,
106108
**extra: Any
107109
) -> _T: ...
108110
def put(
@@ -112,7 +114,7 @@ class _RequestFactory(Generic[_T]):
112114
content_type: str = ...,
113115
secure: bool = ...,
114116
*,
115-
headers: dict[str, Any] | None = ...,
117+
headers: Mapping[str, Any] | None = ...,
116118
**extra: Any
117119
) -> _T: ...
118120
def patch(
@@ -122,7 +124,7 @@ class _RequestFactory(Generic[_T]):
122124
content_type: str = ...,
123125
secure: bool = ...,
124126
*,
125-
headers: dict[str, Any] | None = ...,
127+
headers: Mapping[str, Any] | None = ...,
126128
**extra: Any
127129
) -> _T: ...
128130
def delete(
@@ -132,7 +134,7 @@ class _RequestFactory(Generic[_T]):
132134
content_type: str = ...,
133135
secure: bool = ...,
134136
*,
135-
headers: dict[str, Any] | None = ...,
137+
headers: Mapping[str, Any] | None = ...,
136138
**extra: Any
137139
) -> _T: ...
138140
def generic(
@@ -143,7 +145,7 @@ class _RequestFactory(Generic[_T]):
143145
content_type: str | None = ...,
144146
secure: bool = ...,
145147
*,
146-
headers: dict[str, Any] | None = ...,
148+
headers: Mapping[str, Any] | None = ...,
147149
**extra: Any
148150
) -> _T: ...
149151

@@ -192,7 +194,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
192194
enforce_csrf_checks: bool = ...,
193195
raise_request_exception: bool = ...,
194196
*,
195-
headers: dict[str, Any] | None = ...,
197+
headers: Mapping[str, Any] | None = ...,
196198
**defaults: Any
197199
) -> None: ...
198200
def request(self, **request: Any) -> _MonkeyPatchedWSGIResponse: ...
@@ -203,7 +205,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
203205
follow: bool = ...,
204206
secure: bool = ...,
205207
*,
206-
headers: dict[str, Any] | None = ...,
208+
headers: Mapping[str, Any] | None = ...,
207209
**extra: Any
208210
) -> _MonkeyPatchedWSGIResponse: ...
209211
def post( # type: ignore
@@ -214,7 +216,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
214216
follow: bool = ...,
215217
secure: bool = ...,
216218
*,
217-
headers: dict[str, Any] | None = ...,
219+
headers: Mapping[str, Any] | None = ...,
218220
**extra: Any
219221
) -> _MonkeyPatchedWSGIResponse: ...
220222
def head( # type: ignore
@@ -224,7 +226,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
224226
follow: bool = ...,
225227
secure: bool = ...,
226228
*,
227-
headers: dict[str, Any] | None = ...,
229+
headers: Mapping[str, Any] | None = ...,
228230
**extra: Any
229231
) -> _MonkeyPatchedWSGIResponse: ...
230232
def trace( # type: ignore
@@ -234,7 +236,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
234236
follow: bool = ...,
235237
secure: bool = ...,
236238
*,
237-
headers: dict[str, Any] | None = ...,
239+
headers: Mapping[str, Any] | None = ...,
238240
**extra: Any
239241
) -> _MonkeyPatchedWSGIResponse: ...
240242
def put( # type: ignore
@@ -245,7 +247,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
245247
follow: bool = ...,
246248
secure: bool = ...,
247249
*,
248-
headers: dict[str, Any] | None = ...,
250+
headers: Mapping[str, Any] | None = ...,
249251
**extra: Any
250252
) -> _MonkeyPatchedWSGIResponse: ...
251253
def patch( # type: ignore
@@ -256,7 +258,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
256258
follow: bool = ...,
257259
secure: bool = ...,
258260
*,
259-
headers: dict[str, Any] | None = ...,
261+
headers: Mapping[str, Any] | None = ...,
260262
**extra: Any
261263
) -> _MonkeyPatchedWSGIResponse: ...
262264
def delete( # type: ignore
@@ -267,7 +269,7 @@ class Client(ClientMixin, _RequestFactory[_MonkeyPatchedWSGIResponse]):
267269
follow: bool = ...,
268270
secure: bool = ...,
269271
*,
270-
headers: dict[str, Any] | None = ...,
272+
headers: Mapping[str, Any] | None = ...,
271273
**extra: Any
272274
) -> _MonkeyPatchedWSGIResponse: ...
273275

@@ -282,7 +284,7 @@ class AsyncClient(ClientMixin, _AsyncRequestFactory[Awaitable[_MonkeyPatchedASGI
282284
enforce_csrf_checks: bool = ...,
283285
raise_request_exception: bool = ...,
284286
*,
285-
headers: dict[str, Any] | None = ...,
287+
headers: Mapping[str, Any] | None = ...,
286288
**defaults: Any
287289
) -> None: ...
288290
async def request(self, **request: Any) -> _MonkeyPatchedASGIResponse: ...

0 commit comments

Comments
 (0)