h2 icon indicating copy to clipboard operation
h2 copied to clipboard

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

Open jakkdl opened this issue 6 months ago • 1 comments

Mypy 1.16 added --strict-bytes to --strict, and plans to enable it by default in mypy 2.0. As far as I can tell the type hints in this package has not been updated to reflect this, giving false alarms for downstream users.

Pyright also does not promote bytearray/memoryview to bytes with disableBytesTypePromotions defaulting to True.

The one I noticed when updating https://github.com/pgjones/hypercorn/pull/303 was H2Connection.receive_data only accepting bytes for the data parameter, but it only passes data onto FrameBuffer.add_data which should be perfectly capable of also accepting e.g. bytearray.

It's likely you can replace a lot of type hints with collections.abc.Buffer, or at least a protocol which inherits from Buffer + Sized (since FrameBuffer.add_data makes use of len).

jakkdl avatar Aug 08 '25 10:08 jakkdl