-
-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop .read
/.aread
from SyncByteStream
/AsyncByteStream
#2407
Conversation
@@ -13,8 +13,8 @@ async def test_empty_content(): | |||
assert isinstance(stream, httpx.SyncByteStream) | |||
assert isinstance(stream, httpx.AsyncByteStream) | |||
|
|||
sync_content = stream.read() | |||
async_content = await stream.aread() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're matching the style of the other test cases now.
These .read()
/.aread()
operations were only added to this test case so that we'd have coverage of those code lines.
@@ -52,9 +52,7 @@ def __iter__(self) -> Iterator[bytes]: | |||
raise StreamConsumed() | |||
|
|||
self._is_stream_consumed = True | |||
if hasattr(self._stream, "read") and not isinstance( | |||
self._stream, SyncByteStream | |||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The and not isinstance(self._stream, SyncByteStream)
is what prompted me to clean these up.
It's such an oddly confusing branch - I couldn't figure out why it existed.
"Treat file-like objects as file-like objects, except for this one specific case".
No thanks.
status_code, headers, stream, extensions = transport.handle_request(...) | ||
try: | ||
... | ||
finally: | ||
stream.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example from the old-style Transport API.
We had .read()
so that users could eg. stream.read()
here.
The Transport API now just returns fully fledged responses, so this is redundant.
Thanks for the review @michaeloliverx. |
...How should we handle that generally? |
I think this is okay, maybe if you are personally reviewing something you can go ahead and merge it yourself. |
We have a leftover bit of API on
SyncByteStream
/AsyncByteStream
that is a hangover from when we were designing the Transport API.They both have a convenience method for reading the stream, which was added to make testing at the low-level of the Transport API easier. However the methods are a bit kludgy because they don't actually fit the
read(max_bytes)
that Python file interfaces use.I think we can just hard-drop these. They're undocumented, and you don't ever need them. The convenience methods are on the
Response
class.