Skip to content

Commit c9f74e6

Browse files
authored
requests: Allow passing None header values (#11370)
#7773 changed `requests.session.Session` methods to accept None for header values, but didn't do quite the same for the functions in `requests.api`. I think this was a mistake. The functions in `requests.api` just pass through the `headers` argument without doing anything in particular to it. Furthermore, it's useful to be able to pass None as a header value: because `requests.utils.default_headers` sets an `Accept-Encoding` header by default, the easiest way to send a request with no `Accept-Encoding` header is something like `requests.get(url, headers={"Accept-Encoding": None})`. It's annoying to have to construct a `Session` just to pass type-checking. It's a little confusing for the type alias to be called `_HeadersUpdateMapping` in `requests.sessions` but `_HeadersMapping` in `requests.api`; this is because the latter name was already used in other type stubs (`tensorflow.keras.callbacks`), so it seemed best to avoid breaking API.
1 parent 15fa3cf commit c9f74e6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stubs/requests/requests/api.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from typing_extensions import TypeAlias
55
from .models import Response
66
from .sessions import RequestsCookieJar, _Auth, _Cert, _Data, _Files, _HooksInput, _Params, _TextMapping, _Timeout, _Verify
77

8-
_HeadersMapping: TypeAlias = Mapping[str, str | bytes]
8+
_HeadersMapping: TypeAlias = Mapping[str, str | bytes | None]
99

1010
def request(
1111
method: str | bytes,

0 commit comments

Comments
 (0)