[WIP] Allow None in ClientResponse.reason #3875
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What do these changes do?
Since the work in #3533 is apparently slated for v4.0, this is a backport to v3.5.
Work around an
AssertionError
in v3.5 onClientResponse.raise_for_status()
, when the status is 400 or greater and theClientResponse.reason
isNone
(as opposed to an empty string or something else). The reason is meant purely for "human consumption" and the client's behavior shouldn't depend on it.However, I feel like this might be the wrong place to make this fix. Perhaps real problem is that
message.reason
is allowed to be None, rather than defaulting to an empty string. See, for instance, the expected behavior in Requests: https://github.com/kennethreitz/requests/blob/bedd9284c9646e50c10b3defdf519d4ba479e2c7/requests/models.py#L920-L931This PR is WIP -- should add some kind of test for this, as well as fill out the rest of the checklist items (CONTRIBUTORS.txt, CHANGES). Is any documentation change necessary?
Are there changes in behavior for the user?
None, other than fixing the unexpected
AssertionError
s.Related issue number
#3532
#3533
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.