Skip to content

Commit a46ae91

Browse files
authored
Fix issues in Python<3.12, when using in operator with IntEnum (#54)
* Fix issues in Python<3.12, when using `in` operator with IntEnum * Replace try/except clause in IntEnum with a simple list cast
1 parent 0f39bb1 commit a46ae91

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

jupyter_rtc_core/rooms/yroom.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,14 @@ async def _process_message_queue(self) -> None:
169169
sync_message_subtype = "*"
170170
if message_type == YMessageType.SYNC and len(message) >= 2:
171171
sync_message_subtype = message[1]
172-
172+
173+
174+
173175
# Determine if message is invalid
174-
invalid_message_type = message_type not in YMessageType
175-
invalid_sync_message_type = message_type == YMessageType.SYNC and sync_message_subtype not in YSyncMessageSubtype
176+
# NOTE: In Python 3.12+, we can drop list(...) call
177+
# according to https://docs.python.org/3/library/enum.html#enum.EnumType.__contains__
178+
invalid_message_type = message_type not in list(YMessageType)
179+
invalid_sync_message_type = message_type == YMessageType.SYNC and sync_message_subtype not in list(YSyncMessageSubtype)
176180
invalid_message = invalid_message_type or invalid_sync_message_type
177181

178182
# Handle invalid messages by logging a warning and ignoring

0 commit comments

Comments
 (0)