Skip to content

Broaden receive data buffer types - #197

Open
Mirochill wants to merge 2 commits into
python-hyper:masterfrom
Mirochill:fix-186-buffer-types
Open

Mirochill wants to merge 2 commits into
python-hyper:masterfrom
Mirochill:fix-186-buffer-types

Conversation

@Mirochill

@Mirochill Mirochill commented May 18, 2026 •

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
Mirochill marked this pull request as ready for review May 18, 2026 20:57
Comment thread h11/_connection.py Outdated
Comment thread h11/_receivebuffer.py Outdated
Comment thread h11/tests/test_connection.py Outdated


@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.

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.

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

@Mirochill

Copy link
Copy Markdown
Author

Applied the suggested Buffer annotation via a TYPE_CHECKING-only typing_extensions import, without adding a runtime dependency. The parametrized test now uses a specific Callable type instead of Any. All 80 h11 tests pass on Python 3.12. Current mypy reports the same 32 diagnostics in the baseline and updated trees; no new diagnostic was introduced.

Updated in ed01bb3.

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