Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Nov 6, 2023
1 parent c5dbc6f commit 813376f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions plugins/kernels/fps_kernels/kernel_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
self.session_id = uuid.uuid4().hex
self.msg_cnt = 0
self.execute_requests: Dict[str, Dict[str, asyncio.Queue]] = {}
self.comm_messages = asyncio.Queue()
self.comm_messages: asyncio.Queue = asyncio.Queue()
self.tasks: List[asyncio.Task] = []

async def restart(self, startup_timeout: float = float("inf")) -> None:
Expand Down Expand Up @@ -176,15 +176,18 @@ async def _handle_iopub(self, msg_id: str, ycell: Map) -> None:
ycell["execution_count"] = msg["content"]["execution_count"]

async def _handle_comms(self) -> None:
if self.yjs is None:
return

while True:
msg = await self.comm_messages.get()
msg_type = msg["header"]["msg_type"]
if msg_type == "comm_open":
comm_id = msg["content"]["comm_id"]
comm = Comm(comm_id, self.shell_channel, self.session_id, self.key)
self.yjs.widgets.comm_open(msg, comm)
self.yjs.widgets.comm_open(msg, comm) # type: ignore
elif msg_type == "comm_msg":
self.yjs.widgets.comm_msg(msg)
self.yjs.widgets.comm_msg(msg) # type: ignore

async def _wait_for_ready(self, timeout):
deadline = time.time() + timeout
Expand Down Expand Up @@ -213,18 +216,18 @@ async def _handle_outputs(self, outputs: Array, msg: Dict[str, Any]):
msg_type = msg["header"]["msg_type"]
content = msg["content"]
if msg_type == "stream":
if (not outputs) or (outputs[-1]["name"] != content["name"]):
if (not outputs) or (outputs[-1]["name"] != content["name"]): # type: ignore
outputs.append({"name": content["name"], "output_type": msg_type, "text": []})
outputs[-1]["text"].append(content["text"])
outputs[-1]["text"].append(content["text"]) # type: ignore
elif msg_type in ("display_data", "execute_result"):
if "application/vnd.jupyter.ywidget-view+json" in content["data"]:
# this is a collaborative widget
model_id = content["data"]["application/vnd.jupyter.ywidget-view+json"]["model_id"]
if self.yjs is not None:
if model_id in self.yjs.widgets.widgets:
doc = self.yjs.widgets.widgets[model_id]["model"].ydoc
if model_id in self.yjs.widgets.widgets: # type: ignore
doc = self.yjs.widgets.widgets[model_id]["model"].ydoc # type: ignore
path = f"ywidget:{doc.guid}"
await self.yjs.room_manager.websocket_server.get_room(path, ydoc=doc)
await self.yjs.room_manager.websocket_server.get_room(path, ydoc=doc) # type: ignore
outputs.append(doc)
else:
outputs.append(
Expand Down
4 changes: 2 additions & 2 deletions plugins/yjs/fps_yjs/ywidgets/widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pkg_resources
from pycrdt import TransactionEvent
from ypywidgets.utils import (
from ypywidgets.utils import ( # type: ignore
YMessageType,
YSyncMessageType,
create_update_message,
Expand Down Expand Up @@ -44,7 +44,7 @@ def comm_msg(self, msg) -> None:
ydoc.observe(self._send)

def _send(self, event: TransactionEvent):
update = event.get_update()
update = event.get_update() # type: ignore
message = create_update_message(update)
try:
self.comm.send(buffers=[message])
Expand Down

0 comments on commit 813376f

Please sign in to comment.