requests: allow str and bytes for fileobj in files parameter#7728
Merged
Conversation
AlexWaygood
reviewed
Apr 27, 2022
Member
AlexWaygood
left a comment
There was a problem hiding this comment.
The implementation looks like it can be str, bytes, or anything with a .read() method: https://github.com/psf/requests/blob/31a89d9c8463c3394ca00f408f4b86d814421a09/requests/models.py#L160-L161
Rather than using IO[Any], we could make it even more permissive, and just use _typeshed.SupportsRead:
typeshed/stdlib/_typeshed/__init__.pyi
Lines 180 to 181 in 1f2a970
Contributor
Author
|
Good one, done! Kept the |
Member
|
I've confirmed that this annotation will allow objects with a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Some people are having issues with this one, see #7724
Documentation says to pass a "file-like-object". Implementation allows for
str,bytes,bytearrayor anything that implements.read().Left
bytearrayout for now because urllib3 documentsstrandbytesas valid in RequestField in the next major version.Resolves #7724