Add Response.ajson
#1639
-
|
Since there's already Current Solutiondata = json.loads(await response.aread())
# OR
await response.aread()
data = response.json()ImplementationThe implementation would be fairly easy: class Response:
...
async def ajson(self, **kwargs: Any) -> Any:
await self.aread()
return self.json(**kwargs) |
Beta Was this translation helpful? Give feedback.
Answered by
lovelydinosaur
May 17, 2021
Replies: 1 comment
-
|
So, this wouldn’t make sense as a counterpart because Let’s explain that more clearly. There’s no need for an r = await client.get(...)
r.json() # There’s no I/O occurring here.The only case where you need to explicitly perform I/O is in the streaming case. async with client.stream(...) as r:
await r.aread()
r.json() # Can only call .json once we’ve loaded the response body.Which anyway matches the style you’d need to use in the sync case... with client.stream(...) as r:
r.read()
r.json() # Can only call .json once we’ve loaded the response body. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ToxicKidz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, this wouldn’t make sense as a counterpart because
.json()doesn’t read the response body.Let’s explain that more clearly. There’s no need for an
ajson(), because this already works just fine...The only case where you need to explicitly perform I/O is in the streaming case.
Which anyway matches the style you’d need to use in the sync case...