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

BytesMessage.data is a bytearray but type-hinted as bytes #185

Open
frankie567 opened this issue Jul 12, 2023 · 1 comment
Open

BytesMessage.data is a bytearray but type-hinted as bytes #185

frankie567 opened this issue Jul 12, 2023 · 1 comment

Comments

@frankie567
Copy link

I'm using wsproto in my library httpx-ws. One contributor reported in frankie567/httpx-ws#38, that the data property of BytesMessage is actually a bytearray at runtime, but it's typed as bytes.

Reproducible example

from wsproto import WSConnection, ConnectionType
from wsproto.events import Request, BytesMessage, AcceptConnection

client = WSConnection(ConnectionType.CLIENT)
server = WSConnection(ConnectionType.SERVER)

msg = client.send(Request(host='echo.websocket.org', target='/'))
server.receive_data(msg)

msg = server.send(AcceptConnection())
client.receive_data(msg)

msg = server.send(BytesMessage(b"Hello"))
client.receive_data(msg)

for event in client.events():
    if isinstance(event, BytesMessage):
        print(type(event.data))  # bytearray

Additional comment

It's not really a problem since bytes and bytearray are nearly the same, but from type-hints point-of-view, maybe BytesMessage.data should be typed as bytearray.

@njsmith
Copy link
Member

njsmith commented Jul 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants