Skip to content

Extend confusing type signature of `java.nio.ByteBuffer`.

Nico Madysa requested to merge (removed):extend-bytebuffer-signature into master

The signatures of ByteBuffer.get(), .put() and .wrap() claim to only accept List[int], while they also accept any ByteString (i.e. bytes, bytearray and memoryview).

Only annotating List[int] suggests that any bytes object first has to be converted via list(); but this is wrong! list(bytes(...)) gives a list of integers in the range 0..256 (unsigned char), but ByteBuffer expects integers in the range -128..128 (signed char).

The only reasonable way to get unsigned chars into ByteBuffer is to pass them as bytes unmodified, which conflicts with the previous type signature.

PS: As per the Python docs, bytes is a convenience type annotation that covers any ByteString, so that's what I went with.

Merge request reports