FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Broaden receive data buffer types by Mirochill · Pull Request #197 · python-hyper/h11 · GitHub

Broaden receive data buffer types - #197

Open
Mirochill wants to merge 1 commit into
python-hyper:masterfrom
Mirochill:fix-186-buffer-types
Open

Broaden receive data buffer types#197
Mirochill wants to merge 1 commit into
python-hyper:masterfrom
Mirochill:fix-186-buffer-types

Conversation

Mirochill commented May 18, 2026
edited
Loading

Copy link
Copy Markdown

Summary

  • widen Connection.receive_data() and the internal receive buffer annotations to accept bytearray and memoryview alongside bytes
  • add a regression test covering both supported bytes-like inputs
  • document the backward-compatible API expansion in the news fragment

Why

Issue #186 points out that receive_data() already operates on bytes-like input, but its public annotation is still narrower than the runtime behavior. Widening the concrete accepted types removes false positives for downstream users adopting stricter bytes checking while keeping this patch intentionally small for h11's current typing/tooling baseline.

Validation

  • Not run locally
  • Performed static review of the receive path and confirmed Connection.receive_data() forwards directly into ReceiveBuffer.__iadd__().
  • Verified the patch shape with git diff --check.
  • Relying on the repository's remote CI for execution feedback.

Fixes #186.

Mirochill marked this pull request as ready for review May 18, 2026 20:57
Comment thread h11/_connection.py
return (bytes(self._receive_buffer), self._receive_buffer_closed)

def receive_data(self, data: bytes) -> None:
def receive_data(self, data: Union[bytes, bytearray, memoryview]) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It would be better to use collections.abc.Buffer for Python >= 3.12, as introduced in PEP 688. Alternatively, you can use if typing.TYPE_CHECKING: from typing_extensions import Buffer, which avoids a runtime dependency on typing_extensions.

Comment thread h11/_receivebuffer.py

def __iadd__(self, byteslike: Union[bytes, bytearray]) -> "ReceiveBuffer":
def __iadd__(
self, byteslike: Union[bytes, bytearray, memoryview]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ditto



@pytest.mark.parametrize("data_wrapper", [bytearray, memoryview])
def test_receive_data_accepts_byteslike_objects(data_wrapper: Any) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does this parameter need to be Any?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No. This is just statistically generated spam. This account is brand new and spamming tonnes of projects

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update types to adhere to --strict-bytes / PEP688

3 participants


Back | FazBrowse Home | New Git URL