Repository navigation
Tweak .stream() API - #1026
Tweak .stream() API#1026florimondmanca wants to merge 3 commits into
Conversation
98dca73 to
3c1aac8
Compare
yeraydiazdiaz
left a comment
There was a problem hiding this comment.
This looks really nice but I have to admit I did a double take reading async with await ... 😄
I like the approach and don't mind paying the price of a breaking change pre 1.0, it's worth it.
Nice job as always @florimondmanca 💯
|
Thanks! I need to do a pass on docs (and highlight that the extra await there isn’t a typo 🤣). |
|
Grand. Will aim to take a look this week. Potentially some mixed thoughts about it, but needs a proper look! 🙂 |
83114ee to
3f27541
Compare
|
So my reservations around this are to do with the Changing things this way around would mean that...
So I'm not yet convinced that it's clear if we shouldn't just stick with helping developers down the straight and narrow path, while allowing The pointer to trio's |
|
Those are valid points @tomchristie, thanks. Opened #1046 to explore the "just document how to use manual streaming" path, and I think it's the most convincing option. Closing this in favor of #1046 for now… |
Refs #830
A proof-of-concept (but working) PR to illustrate #830 (comment)
Response. (This brings us closer to what Requests does.).stream()return aResponse, allowing both context-managed and non-context-managed usage with an equivalent level of user experience.The high-level
httpx.stream()is kept to context-managed only because we also need to close the client on exit (and it would be awkward to eg implement a close callback API on theResponseclass just for this internal use case).The breaking change here is that users would need to use
async with await client.stream()in the async context-managed use case (extraawait). This usage might be surprising but in line with other things such as trio'sopen_file()API.