Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requests: Allow passing None header values #11370

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

cjwatson
Copy link
Contributor

@cjwatson cjwatson commented Feb 6, 2024

#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.

This comment has been minimized.

python#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.
@cjwatson cjwatson force-pushed the requests-api-headers-None branch from 623346c to ec55ac8 Compare February 6, 2024 15:30
Copy link
Contributor

github-actions bot commented Feb 6, 2024

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit c9f74e6 into python:main Feb 17, 2024
45 checks passed
@cjwatson cjwatson deleted the requests-api-headers-None branch March 26, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants