Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/deepgram/listen/v2/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ def __init__(self, *, websocket: websockets_sync_connection.Connection):

def _is_binary_message(self, message: typing.Any) -> bool:
"""Determine if a message is binary data."""
return isinstance(message, (bytes, bytearray))
# Use direct type comparison for the most common cases for slightly improved performance,
# and fall back to isinstance only if necessary.
msg_type = type(message)
if msg_type is bytes or msg_type is bytearray:
return True
return False

def _handle_binary_message(self, message: bytes) -> typing.Any:
"""Handle a binary message (returns as-is)."""
Expand Down