h11 icon indicating copy to clipboard operation
h11 copied to clipboard

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

Open jakkdl opened this issue 4 months ago • 0 comments

This is a near copy-paste of https://github.com/python-hyper/h2/issues/1305

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 Connection.receive_data only accepting bytes for the data parameter, but it only passes data onto ReceiveBuffer.__iadd__ which explicitly accepts bytes | bytearray. Even this could be widened, as bytearray.__iadd__ effectively accepts Buffer (though I'm not sure if the ReadableBuffer distinction matters, probably not)

It's likely you can replace a lot of type hints with collections.abc.Buffer, or other protocols.

jakkdl avatar Aug 08 '25 10:08 jakkdl