Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3db49a

Browse files
authored
requests: improve _Data type (#8762)
requests: improve _Data type This allows to pass an Iterable[bytes] for streaming request data.
1 parent dba47e0 commit b3db49a

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

stubs/requests/requests/sessions.pyi

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from _typeshed import Self, SupportsItems, SupportsRead
22
from collections.abc import Callable, Iterable, Mapping, MutableMapping
3-
from typing import IO, Any, Union
3+
from typing import Any, Union
44
from typing_extensions import TypeAlias, TypedDict
55

66
from urllib3._collections import RecentlyUsedContainer
@@ -45,7 +45,25 @@ class SessionRedirectMixin:
4545
def rebuild_proxies(self, prepared_request, proxies): ...
4646
def should_strip_auth(self, old_url, new_url): ...
4747

48-
_Data: TypeAlias = str | bytes | Mapping[str, Any] | Iterable[tuple[str, str | None]] | IO[Any]
48+
_Data: TypeAlias = (
49+
# used in requests.models.PreparedRequest.prepare_body
50+
#
51+
# case: is_stream
52+
# see requests.adapters.HTTPAdapter.send
53+
# will be sent directly to http.HTTPConnection.send(...) (through urllib3)
54+
Iterable[bytes]
55+
# case: not is_stream
56+
# will be modified before being sent to urllib3.HTTPConnectionPool.urlopen(body=...)
57+
# see requests.models.RequestEncodingMixin._encode_params
58+
# see requests.models.RequestEncodingMixin._encode_files
59+
# note that keys&values are converted from Any to str by urllib.parse.urlencode
60+
| str
61+
| bytes
62+
| SupportsRead[str | bytes]
63+
| list[tuple[Any, Any]]
64+
| tuple[tuple[Any, Any], ...]
65+
| Mapping[Any, Any]
66+
)
4967
_Auth: TypeAlias = Union[tuple[str, str], _auth.AuthBase, Callable[[PreparedRequest], PreparedRequest]]
5068
_Cert: TypeAlias = Union[str, tuple[str, str]]
5169
# Files is passed to requests.utils.to_key_val_list()

0 commit comments

Comments
 (0)