Skip to content
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

Pure ByteStream interface #133

Merged
merged 5 commits into from
Aug 6, 2020
Merged

Pure ByteStream interface #133

merged 5 commits into from
Aug 6, 2020

Conversation

tomchristie
Copy link
Member

@tomchristie tomchristie commented Aug 5, 2020

This pull request ensures that our AsyncByteStream and SyncByteStream classes are pure interface classes, without any implementations themselves.

It also introduces the following concrete implementations, which act as helpful classes for developers, so that it's not always strictly necessary to implement a concrete class.

stream = httpcore.PlainByteStream(b"123")
stream = httpcore.IteratorByteStream(iterator=...)  # Optionally, also `close_func=...`.
stream = httpcore.AsyncIteratorByteStream(aiterator=...)  # Optionally, also `aclose_func=...`.

Developers don't need to use our concrete implementations, as they could instead provide their own implementations, but this change gives us both a nice purity of interface, and the convenience of providing a few very basic implementations.

@tomchristie tomchristie added this to the 0.10.0 milestone Aug 5, 2020
@tomchristie tomchristie changed the title Pyte ByteStream interface Pure ByteStream interface Aug 5, 2020
@tomchristie tomchristie added the enhancement New feature or request label Aug 5, 2020
Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions on naming, but 💯 sold on the idea!

httpcore/_bytestreams.py Outdated Show resolved Hide resolved
httpcore/_bytestreams.py Outdated Show resolved Hide resolved
@tomchristie tomchristie merged commit 2b85b00 into master Aug 6, 2020
@tomchristie tomchristie deleted the pure-bytestream-interface branch August 6, 2020 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants