deephaven / deephaven-core

Deephaven Community Core
Other
257 stars 80 forks source link

`MessageStream.on_data` type hints do not match the actual data types #6267

Open chipkent opened 1 month ago

chipkent commented 1 month ago

I've been working to create a new plugin from scratch to help with our documentation. In the process, I found a bug that caused me to waste a reasonable amount of time. It is subtle.

We have the signature:

MessageStream.on_data(self, payload: bytes, references: List[Any]):

In practice, payload is not bytes but is a java byte array. This deviation from the typehints was a PITA to find. isinstance indicates that the java type is neither bytes nor bytearray.

From looking at the plugin code, it looks like there are a number of other on_data methods with bytes indicated. Is there any reason we can't actually pass in bytes?

Additionally, a small bit of code indicates that calling bytes() on something that is already bytes just returns bytes, so it should be safe to make a change that will not break users.

x = b'`1234'
print(type(x))

xx = bytes(x)

print( x == xx )
<class 'bytes'>
True