Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chipkent opened this issue Oct 22, 2024 · 0 comments
Open

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

chipkent opened this issue Oct 22, 2024 · 0 comments

Comments

@chipkent
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants