Skip to content

Commit 173c7d2

Browse files
glyphKriechi
authored andcommitted
bytes are still a valid type here
1 parent f7afa86 commit 173c7d2

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/wsproto/events.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Events that result from processing data on a WebSocket connection.
66
"""
7+
78
from __future__ import annotations
89

910
from abc import ABC
@@ -193,7 +194,7 @@ def response(self) -> CloseConnection:
193194
return CloseConnection(code=self.code, reason=self.reason)
194195

195196

196-
T = TypeVar("T", bytes, bytearray, str)
197+
T = TypeVar("T", bytes | bytearray, str)
197198

198199

199200
@dataclass(frozen=True)
@@ -242,26 +243,24 @@ class TextMessage(Message[str]): # pylint: disable=unsubscriptable-object
242243
and reassemble these chunks to get the full message.
243244
"""
244245

245-
data: str
246-
247246

248247
@dataclass(frozen=True)
249-
class BytesMessage(Message[bytearray]): # pylint: disable=unsubscriptable-object
248+
class BytesMessage(
249+
Message[bytearray | bytes] # pylint: disable=unsubscriptable-object
250+
):
250251
"""
251252
Fired when a data frame with BINARY payload is received.
252253
253254
Fields:
254255
255256
.. attribute:: data
256257
257-
The message data as bytearray, can be decoded as UTF-8 for
258+
The message data as bytes or a bytearray, can be decoded as UTF-8 for
258259
TEXT messages. This only represents a single chunk of data and
259260
not a full WebSocket message. You need to buffer and
260261
reassemble these chunks to get the full message.
261262
"""
262263

263-
data: bytearray
264-
265264

266265
@dataclass(frozen=True)
267266
class Ping(Event):

0 commit comments

Comments
 (0)