[requests] Add a _JSON type alias (#14064)

This commit is contained in:
Sebastian Rittau
2025-05-14 15:38:10 +02:00
committed by GitHub
parent 9951e66a5e
commit 51db4055d0
3 changed files with 27 additions and 26 deletions
+9 -10
View File
@@ -1,9 +1,8 @@
from _typeshed import Incomplete
from collections.abc import Mapping
from http.cookiejar import CookieJar
from typing_extensions import TypeAlias
from .models import Response
from .models import _JSON, Response
from .sessions import _Auth, _Cert, _Data, _Files, _HooksInput, _Params, _TextMapping, _Timeout, _Verify
_HeadersMapping: TypeAlias = Mapping[str, str | bytes | None]
@@ -25,7 +24,7 @@ def request(
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def get(
url: str | bytes,
@@ -43,7 +42,7 @@ def get(
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def options(
url: str | bytes,
@@ -61,7 +60,7 @@ def options(
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def head(
url: str | bytes,
@@ -79,12 +78,12 @@ def head(
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def post(
url: str | bytes,
data: _Data | None = None,
json: Incomplete | None = None,
json: _JSON | None = None,
*,
params: _Params | None = ...,
headers: _HeadersMapping | None = ...,
@@ -115,7 +114,7 @@ def put(
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def patch(
url: str | bytes,
@@ -133,7 +132,7 @@ def patch(
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def delete(
url: str | bytes,
@@ -151,5 +150,5 @@ def delete(
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
+5 -3
View File
@@ -3,7 +3,7 @@ from _typeshed import Incomplete, MaybeNone, Unused
from collections.abc import Callable, Iterator
from json import JSONDecoder
from typing import Any
from typing_extensions import Self
from typing_extensions import Self, TypeAlias
from urllib3 import exceptions as urllib3_exceptions, fields, filepost, util
from urllib3.response import HTTPResponse
@@ -13,6 +13,8 @@ from .adapters import HTTPAdapter
from .cookies import RequestsCookieJar
from .structures import CaseInsensitiveDict as CaseInsensitiveDict
_JSON: TypeAlias = Any # any object that can be serialized to JSON
default_hooks = hooks.default_hooks
HTTPBasicAuth = auth.HTTPBasicAuth
cookiejar_from_dict = cookies.cookiejar_from_dict
@@ -63,7 +65,7 @@ class Request(RequestHooksMixin):
headers: Incomplete
files: Incomplete
data: Incomplete
json: Incomplete
json: _JSON | None
params: Incomplete
auth: Incomplete
cookies: Incomplete
@@ -78,7 +80,7 @@ class Request(RequestHooksMixin):
auth=None,
cookies=None,
hooks=None,
json=None,
json: _JSON | None = None,
) -> None: ...
def prepare(self) -> PreparedRequest: ...
+13 -13
View File
@@ -1,10 +1,10 @@
from _typeshed import Incomplete, SupportsItems, SupportsRead, Unused
from _typeshed import SupportsItems, SupportsRead, Unused
from collections.abc import Callable, Iterable, Mapping, MutableMapping
from typing import Any, TypedDict
from typing_extensions import Self, TypeAlias
from . import adapters, auth as _auth, compat, cookies, exceptions, hooks, models, status_codes, utils
from .models import Response
from .models import _JSON, Response
from .structures import CaseInsensitiveDict as CaseInsensitiveDict
_BaseAdapter: TypeAlias = adapters.BaseAdapter
@@ -44,10 +44,10 @@ class SessionRedirectMixin:
resp,
req,
stream: bool = False,
timeout: Incomplete | None = None,
timeout=None,
verify: bool = True,
cert: Incomplete | None = None,
proxies: Incomplete | None = None,
cert=None,
proxies=None,
yield_requests: bool = False,
**adapter_kwargs,
): ...
@@ -151,7 +151,7 @@ class Session(SessionRedirectMixin):
stream: bool | None = None,
verify: _Verify | None = None,
cert: _Cert | None = None,
json: Incomplete | None = None,
json: _JSON | None = None,
) -> Response: ...
def get(
self,
@@ -170,7 +170,7 @@ class Session(SessionRedirectMixin):
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def options(
self,
@@ -189,7 +189,7 @@ class Session(SessionRedirectMixin):
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def head(
self,
@@ -208,13 +208,13 @@ class Session(SessionRedirectMixin):
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def post(
self,
url: str | bytes,
data: _Data | None = None,
json: Incomplete | None = None,
json: _JSON | None = None,
*,
params: _Params | None = ...,
headers: _HeadersUpdateMapping | None = ...,
@@ -246,7 +246,7 @@ class Session(SessionRedirectMixin):
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def patch(
self,
@@ -265,7 +265,7 @@ class Session(SessionRedirectMixin):
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def delete(
self,
@@ -284,7 +284,7 @@ class Session(SessionRedirectMixin):
stream: bool | None = ...,
verify: _Verify | None = ...,
cert: _Cert | None = ...,
json: Incomplete | None = ...,
json: _JSON | None = None,
) -> Response: ...
def send(
self,