chore: support JSONRepsonse dumps callable return type bytes#3000
Merged
Conversation
JSONRepsonse dumps param type to realityJSONRepsonse dumps callable return type to AnyStr
f390d04 to
6ba5dc7
Compare
JSONRepsonse dumps callable return type to AnyStrJSONRepsonse dumps callable return type bytes
the `dumps` parameter is used to serialize the `JSONResponse` to text. this is often done with python's built in `json.dumps` but other times via `orjson.dumps` however, to use `orjson.dumps`, you have to ignore the suggested type (`str`) because `orjson.dumps` returns a `bytes` to correct this, the typing for the dumps callable has been switched to be an `AnyStr` so either `bytes` or `str` returning callable can be passed
imnotjames
commented
Sep 27, 2024
Contributor
Author
|
For some reason the type checking is acting up - but it's on things that I don't think are related. Happy to fix as needed with a bit of direction, though. |
ahopkins
approved these changes
Dec 31, 2024
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.
the
dumpsparameter is used to serialize theJSONResponseto text. this is often done with python's built injson.dumpsbut other times viaujson.dumpsandorjson.dumpshowever, to use
orjson.dumpsas suggested in the docs, you have to ignore the suggested type (str) becauseorjson.dumpsreturns abytesto correct this, the typing for the dumps callable has been switched to be an
Callable[..., AnyStr]so eitherbytesorstrreturning callable can be passedthis was previously done in #2193 but for some reason not brought over to
JSONResponse?