Skip to content

Commit 51db405

Browse files
authored
[requests] Add a _JSON type alias (#14064)
1 parent 9951e66 commit 51db405

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

stubs/requests/requests/api.pyi

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Mapping
32
from http.cookiejar import CookieJar
43
from typing_extensions import TypeAlias
54

6-
from .models import Response
5+
from .models import _JSON, Response
76
from .sessions import _Auth, _Cert, _Data, _Files, _HooksInput, _Params, _TextMapping, _Timeout, _Verify
87

98
_HeadersMapping: TypeAlias = Mapping[str, str | bytes | None]
@@ -25,7 +24,7 @@ def request(
2524
stream: bool | None = ...,
2625
verify: _Verify | None = ...,
2726
cert: _Cert | None = ...,
28-
json: Incomplete | None = ...,
27+
json: _JSON | None = None,
2928
) -> Response: ...
3029
def get(
3130
url: str | bytes,
@@ -43,7 +42,7 @@ def get(
4342
stream: bool | None = ...,
4443
verify: _Verify | None = ...,
4544
cert: _Cert | None = ...,
46-
json: Incomplete | None = ...,
45+
json: _JSON | None = None,
4746
) -> Response: ...
4847
def options(
4948
url: str | bytes,
@@ -61,7 +60,7 @@ def options(
6160
stream: bool | None = ...,
6261
verify: _Verify | None = ...,
6362
cert: _Cert | None = ...,
64-
json: Incomplete | None = ...,
63+
json: _JSON | None = None,
6564
) -> Response: ...
6665
def head(
6766
url: str | bytes,
@@ -79,12 +78,12 @@ def head(
7978
stream: bool | None = ...,
8079
verify: _Verify | None = ...,
8180
cert: _Cert | None = ...,
82-
json: Incomplete | None = ...,
81+
json: _JSON | None = None,
8382
) -> Response: ...
8483
def post(
8584
url: str | bytes,
8685
data: _Data | None = None,
87-
json: Incomplete | None = None,
86+
json: _JSON | None = None,
8887
*,
8988
params: _Params | None = ...,
9089
headers: _HeadersMapping | None = ...,
@@ -115,7 +114,7 @@ def put(
115114
stream: bool | None = ...,
116115
verify: _Verify | None = ...,
117116
cert: _Cert | None = ...,
118-
json: Incomplete | None = ...,
117+
json: _JSON | None = None,
119118
) -> Response: ...
120119
def patch(
121120
url: str | bytes,
@@ -133,7 +132,7 @@ def patch(
133132
stream: bool | None = ...,
134133
verify: _Verify | None = ...,
135134
cert: _Cert | None = ...,
136-
json: Incomplete | None = ...,
135+
json: _JSON | None = None,
137136
) -> Response: ...
138137
def delete(
139138
url: str | bytes,
@@ -151,5 +150,5 @@ def delete(
151150
stream: bool | None = ...,
152151
verify: _Verify | None = ...,
153152
cert: _Cert | None = ...,
154-
json: Incomplete | None = ...,
153+
json: _JSON | None = None,
155154
) -> Response: ...

stubs/requests/requests/models.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from _typeshed import Incomplete, MaybeNone, Unused
33
from collections.abc import Callable, Iterator
44
from json import JSONDecoder
55
from typing import Any
6-
from typing_extensions import Self
6+
from typing_extensions import Self, TypeAlias
77

88
from urllib3 import exceptions as urllib3_exceptions, fields, filepost, util
99
from urllib3.response import HTTPResponse
@@ -13,6 +13,8 @@ from .adapters import HTTPAdapter
1313
from .cookies import RequestsCookieJar
1414
from .structures import CaseInsensitiveDict as CaseInsensitiveDict
1515

16+
_JSON: TypeAlias = Any # any object that can be serialized to JSON
17+
1618
default_hooks = hooks.default_hooks
1719
HTTPBasicAuth = auth.HTTPBasicAuth
1820
cookiejar_from_dict = cookies.cookiejar_from_dict
@@ -63,7 +65,7 @@ class Request(RequestHooksMixin):
6365
headers: Incomplete
6466
files: Incomplete
6567
data: Incomplete
66-
json: Incomplete
68+
json: _JSON | None
6769
params: Incomplete
6870
auth: Incomplete
6971
cookies: Incomplete
@@ -78,7 +80,7 @@ class Request(RequestHooksMixin):
7880
auth=None,
7981
cookies=None,
8082
hooks=None,
81-
json=None,
83+
json: _JSON | None = None,
8284
) -> None: ...
8385
def prepare(self) -> PreparedRequest: ...
8486

stubs/requests/requests/sessions.pyi

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from _typeshed import Incomplete, SupportsItems, SupportsRead, Unused
1+
from _typeshed import SupportsItems, SupportsRead, Unused
22
from collections.abc import Callable, Iterable, Mapping, MutableMapping
33
from typing import Any, TypedDict
44
from typing_extensions import Self, TypeAlias
55

66
from . import adapters, auth as _auth, compat, cookies, exceptions, hooks, models, status_codes, utils
7-
from .models import Response
7+
from .models import _JSON, Response
88
from .structures import CaseInsensitiveDict as CaseInsensitiveDict
99

1010
_BaseAdapter: TypeAlias = adapters.BaseAdapter
@@ -44,10 +44,10 @@ class SessionRedirectMixin:
4444
resp,
4545
req,
4646
stream: bool = False,
47-
timeout: Incomplete | None = None,
47+
timeout=None,
4848
verify: bool = True,
49-
cert: Incomplete | None = None,
50-
proxies: Incomplete | None = None,
49+
cert=None,
50+
proxies=None,
5151
yield_requests: bool = False,
5252
**adapter_kwargs,
5353
): ...
@@ -151,7 +151,7 @@ class Session(SessionRedirectMixin):
151151
stream: bool | None = None,
152152
verify: _Verify | None = None,
153153
cert: _Cert | None = None,
154-
json: Incomplete | None = None,
154+
json: _JSON | None = None,
155155
) -> Response: ...
156156
def get(
157157
self,
@@ -170,7 +170,7 @@ class Session(SessionRedirectMixin):
170170
stream: bool | None = ...,
171171
verify: _Verify | None = ...,
172172
cert: _Cert | None = ...,
173-
json: Incomplete | None = ...,
173+
json: _JSON | None = None,
174174
) -> Response: ...
175175
def options(
176176
self,
@@ -189,7 +189,7 @@ class Session(SessionRedirectMixin):
189189
stream: bool | None = ...,
190190
verify: _Verify | None = ...,
191191
cert: _Cert | None = ...,
192-
json: Incomplete | None = ...,
192+
json: _JSON | None = None,
193193
) -> Response: ...
194194
def head(
195195
self,
@@ -208,13 +208,13 @@ class Session(SessionRedirectMixin):
208208
stream: bool | None = ...,
209209
verify: _Verify | None = ...,
210210
cert: _Cert | None = ...,
211-
json: Incomplete | None = ...,
211+
json: _JSON | None = None,
212212
) -> Response: ...
213213
def post(
214214
self,
215215
url: str | bytes,
216216
data: _Data | None = None,
217-
json: Incomplete | None = None,
217+
json: _JSON | None = None,
218218
*,
219219
params: _Params | None = ...,
220220
headers: _HeadersUpdateMapping | None = ...,
@@ -246,7 +246,7 @@ class Session(SessionRedirectMixin):
246246
stream: bool | None = ...,
247247
verify: _Verify | None = ...,
248248
cert: _Cert | None = ...,
249-
json: Incomplete | None = ...,
249+
json: _JSON | None = None,
250250
) -> Response: ...
251251
def patch(
252252
self,
@@ -265,7 +265,7 @@ class Session(SessionRedirectMixin):
265265
stream: bool | None = ...,
266266
verify: _Verify | None = ...,
267267
cert: _Cert | None = ...,
268-
json: Incomplete | None = ...,
268+
json: _JSON | None = None,
269269
) -> Response: ...
270270
def delete(
271271
self,
@@ -284,7 +284,7 @@ class Session(SessionRedirectMixin):
284284
stream: bool | None = ...,
285285
verify: _Verify | None = ...,
286286
cert: _Cert | None = ...,
287-
json: Incomplete | None = ...,
287+
json: _JSON | None = None,
288288
) -> Response: ...
289289
def send(
290290
self,

0 commit comments

Comments
 (0)