Skip to content

Commit

Permalink
Fix typing for python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Nov 25, 2024
1 parent 2961450 commit 6111c20
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions python/jupyterlab-chat/jupyterlab_chat/ychat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import asyncio
from functools import partial
from jupyter_ydoc.ybasedoc import YBaseDoc
from typing import Any, Callable, Set
from typing import Any, Callable, Optional, Set
from uuid import uuid4
from pycrdt import Array, ArrayEvent, Map, MapEvent

Expand Down Expand Up @@ -52,13 +52,13 @@ def yusers(self) -> Map:
def ymetadata(self) -> Map:
return self._ymetadata

def get_user(self, username: str) -> dict[str, str] | None:
def get_user(self, username: str) -> Optional[dict[str, str]]:
"""
Returns a message from its id, or None
"""
return self.get_users().get(username, None)

def get_user_by_name(self, name: str) -> dict[str, str] | None:
def get_user_by_name(self, name: str) -> Optional[dict[str, str]]:
"""
Returns a user from its name property, or None.
"""
Expand All @@ -81,7 +81,7 @@ def set_user(self, user: dict[str, str]) -> None:
with self._ydoc.transaction():
self._yusers.update({user["username"]: user})

def get_message(self, id: str) -> tuple[dict | None, int | None]:
def get_message(self, id: str) -> tuple[Optional[dict], Optional[int]]:
"""
Returns a message and its index from its id, or None
"""
Expand Down Expand Up @@ -119,12 +119,12 @@ def update_message(self, message: dict, index: int, append: bool = False):
message["body"] = initial_message["body"] + message["body"]
self._ymessages.insert(index, message)

def set_message(self, message: dict, index: int | None = None, append: bool = False) -> int:
def set_message(self, message: dict, index: Optional[int] = None, append: bool = False) -> int:
"""
Update or append a message.
"""

initial_message: dict | None = None
initial_message: Optional[dict] = None
if index is not None and 0 <= index < len(self._ymessages):
initial_message = self.get_messages()[index]
else:
Expand Down Expand Up @@ -165,7 +165,7 @@ async def create_id(self) -> str:
self.set_id(id)
return id

def get_id(self) -> str | None:
def get_id(self) -> Optional[str]:
"""
Returns the ID of the document.
"""
Expand Down

0 comments on commit 6111c20

Please sign in to comment.