Skip to content

Commit

Permalink
fix typing issues raised by mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
dlqqq committed Oct 18, 2024
1 parent be2fde5 commit 6738a22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Awaitable,
ClassVar,
Dict,
get_args as get_type_args,
List,
Literal,
Optional,
Expand Down Expand Up @@ -265,8 +266,8 @@ async def _default_handle_exc(self, e: Exception, message: HumanChatMessage):
def broadcast_message(self, message: Message):
"""
Broadcasts a message to all WebSocket connections. If there are no
WebSocket connections, this method directly appends to
`self.chat_history`.
WebSocket connections and the message is a chat message, this method
directly appends to `self.chat_history`.
"""
broadcast = False
for websocket in self._root_chat_handlers.values():
Expand All @@ -278,7 +279,9 @@ def broadcast_message(self, message: Message):
break

if not broadcast:
self._chat_history.append(message)
if isinstance(message, get_type_args(ChatMessage)):
cast(ChatMessage, message)
self._chat_history.append(message)

def reply(self, response: str, human_msg: Optional[HumanChatMessage] = None):
"""
Expand Down
8 changes: 4 additions & 4 deletions packages/jupyter-ai/jupyter_ai/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ def loop(self) -> AbstractEventLoop:
def pending_messages(self) -> List[PendingMessage]:
return self.settings["pending_messages"]

@pending_messages.setter
def pending_messages(self, new_pending_messages):
self.settings["pending_messages"] = new_pending_messages

@property
def cleared_message_ids(self) -> Set[str]:
"""Set of `HumanChatMessage.id` that were cleared via `ClearRequest`."""
if "cleared_message_ids" not in self.settings:
self.settings["cleared_message_ids"] = set()
return self.settings["cleared_message_ids"]

@pending_messages.setter
def pending_messages(self, new_pending_messages):
self.settings["pending_messages"] = new_pending_messages

def initialize(self):
self.log.debug("Initializing websocket connection %s", self.request.path)

Expand Down

0 comments on commit 6738a22

Please sign in to comment.