Skip to content

Commit 2a09612

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ba2271d commit 2a09612

File tree

7 files changed

+35
-32
lines changed

7 files changed

+35
-32
lines changed

jupyter_ydoc/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4+
from importlib.metadata import entry_points
5+
46
from ._version import __version__ as __version__
57
from .yblob import YBlob as YBlob
68
from .yfile import YFile as YFile
79
from .ynotebook import YNotebook as YNotebook
810
from .yunicode import YUnicode as YUnicode
911

10-
from importlib.metadata import entry_points
11-
1212
ydocs = {ep.name: ep.load() for ep in entry_points(group="jupyter_ydoc")}

jupyter_ydoc/utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
from typing import Dict, List, Type, Union
54

6-
INT = Type[int]
7-
FLOAT = Type[float]
5+
INT = type[int]
6+
FLOAT = type[float]
87

98

10-
def cast_all(
11-
o: Union[List, Dict], from_type: Union[INT, FLOAT], to_type: Union[FLOAT, INT]
12-
) -> Union[List, Dict]:
9+
def cast_all(o: list | dict, from_type: INT | FLOAT, to_type: FLOAT | INT) -> list | dict:
1310
if isinstance(o, list):
1411
for i, v in enumerate(o):
1512
if type(v) is from_type:

jupyter_ydoc/ybasedoc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Distributed under the terms of the Modified BSD License.
33

44
from abc import ABC, abstractmethod
5-
from typing import Any, Callable, Dict, Optional
5+
from collections.abc import Callable
6+
from typing import Any
67

78
from pycrdt import Awareness, Doc, Map, Subscription, UndoManager
89

@@ -17,10 +18,10 @@ class YBaseDoc(ABC):
1718

1819
_ydoc: Doc
1920
_ystate: Map
20-
_subscriptions: Dict[Any, Subscription]
21+
_subscriptions: dict[Any, Subscription]
2122
_undo_manager: UndoManager
2223

23-
def __init__(self, ydoc: Optional[Doc] = None, awareness: Optional[Awareness] = None):
24+
def __init__(self, ydoc: Doc | None = None, awareness: Awareness | None = None):
2425
"""
2526
Constructs a YBaseDoc.
2627
@@ -100,7 +101,7 @@ def source(self, value: Any):
100101
return self.set(value)
101102

102103
@property
103-
def dirty(self) -> Optional[bool]:
104+
def dirty(self) -> bool | None:
104105
"""
105106
Returns whether the document is dirty.
106107
@@ -120,7 +121,7 @@ def dirty(self, value: bool) -> None:
120121
self._ystate["dirty"] = value
121122

122123
@property
123-
def hash(self) -> Optional[str]:
124+
def hash(self) -> str | None:
124125
"""
125126
Returns the document hash as computed by contents manager.
126127
@@ -140,7 +141,7 @@ def hash(self, value: str) -> None:
140141
self._ystate["hash"] = value
141142

142143
@property
143-
def path(self) -> Optional[str]:
144+
def path(self) -> str | None:
144145
"""
145146
Returns document's path.
146147

jupyter_ydoc/yblob.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4+
from collections.abc import Callable
45
from functools import partial
5-
from typing import Any, Callable, Optional
6+
from typing import Any
67

78
from pycrdt import Awareness, Doc, Map
89

@@ -24,7 +25,7 @@ class YBlob(YBaseDoc):
2425
}
2526
"""
2627

27-
def __init__(self, ydoc: Optional[Doc] = None, awareness: Optional[Awareness] = None):
28+
def __init__(self, ydoc: Doc | None = None, awareness: Awareness | None = None):
2829
"""
2930
Constructs a YBlob.
3031

jupyter_ydoc/ynotebook.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# Distributed under the terms of the Modified BSD License.
33

44
import copy
5+
from collections.abc import Callable
56
from functools import partial
6-
from typing import Any, Callable, Dict, List, Optional
7+
from typing import Any
78
from uuid import uuid4
89

910
from pycrdt import Array, Awareness, Doc, Map, Text
@@ -47,7 +48,7 @@ class YNotebook(YBaseDoc):
4748
}
4849
"""
4950

50-
def __init__(self, ydoc: Optional[Doc] = None, awareness: Optional[Awareness] = None):
51+
def __init__(self, ydoc: Doc | None = None, awareness: Awareness | None = None):
5152
"""
5253
Constructs a YNotebook.
5354
@@ -92,7 +93,7 @@ def cell_number(self) -> int:
9293
"""
9394
return len(self._ycells)
9495

95-
def get_cell(self, index: int) -> Dict[str, Any]:
96+
def get_cell(self, index: int) -> dict[str, Any]:
9697
"""
9798
Returns a cell.
9899
@@ -104,7 +105,7 @@ def get_cell(self, index: int) -> Dict[str, Any]:
104105
"""
105106
return self._cell_to_py(self._ycells[index])
106107

107-
def _cell_to_py(self, ycell: Map) -> Dict[str, Any]:
108+
def _cell_to_py(self, ycell: Map) -> dict[str, Any]:
108109
meta = self._ymeta.to_py()
109110
cell = ycell.to_py()
110111
cell.pop("execution_state", None)
@@ -120,7 +121,7 @@ def _cell_to_py(self, ycell: Map) -> Dict[str, Any]:
120121
del cell["attachments"]
121122
return cell
122123

123-
def append_cell(self, value: Dict[str, Any]) -> None:
124+
def append_cell(self, value: dict[str, Any]) -> None:
124125
"""
125126
Appends a cell.
126127
@@ -130,7 +131,7 @@ def append_cell(self, value: Dict[str, Any]) -> None:
130131
ycell = self.create_ycell(value)
131132
self._ycells.append(ycell)
132133

133-
def set_cell(self, index: int, value: Dict[str, Any]) -> None:
134+
def set_cell(self, index: int, value: dict[str, Any]) -> None:
134135
"""
135136
Sets a cell into indicated position.
136137
@@ -143,7 +144,7 @@ def set_cell(self, index: int, value: Dict[str, Any]) -> None:
143144
ycell = self.create_ycell(value)
144145
self.set_ycell(index, ycell)
145146

146-
def create_ycell(self, value: Dict[str, Any]) -> Map:
147+
def create_ycell(self, value: dict[str, Any]) -> Map:
147148
"""
148149
Creates YMap with the content of the cell.
149150
@@ -193,7 +194,7 @@ def set_ycell(self, index: int, ycell: Map) -> None:
193194
"""
194195
self._ycells[index] = ycell
195196

196-
def get(self) -> Dict:
197+
def get(self) -> dict:
197198
"""
198199
Returns the content of the document.
199200
@@ -227,7 +228,7 @@ def get(self) -> Dict:
227228
nbformat_minor=int(meta.get("nbformat_minor", 0)),
228229
)
229230

230-
def set(self, value: Dict) -> None:
231+
def set(self, value: dict) -> None:
231232
"""
232233
Sets the content of the document.
233234
@@ -251,7 +252,7 @@ def set(self, value: Dict) -> None:
251252
old_ycells_by_id = {ycell["id"]: ycell for ycell in self._ycells}
252253

253254
with self._ydoc.transaction():
254-
new_cell_list: List[dict] = []
255+
new_cell_list: list[dict] = []
255256
retained_cells = set()
256257

257258
# Determine cells to be retained

jupyter_ydoc/yunicode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4+
from collections.abc import Callable
45
from functools import partial
5-
from typing import Any, Callable, Optional
6+
from typing import Any
67

78
from pycrdt import Awareness, Doc, Text
89

@@ -23,7 +24,7 @@ class YUnicode(YBaseDoc):
2324
}
2425
"""
2526

26-
def __init__(self, ydoc: Optional[Doc] = None, awareness: Optional[Awareness] = None):
27+
def __init__(self, ydoc: Doc | None = None, awareness: Awareness | None = None):
2728
"""
2829
Constructs a YUnicode.
2930

tests/test_pycrdt_yjs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ async def test_ypy_yjs_0(yws_server, yjs_client):
6565
ydoc = Doc()
6666
ynotebook = YNotebook(ydoc)
6767
room_name = "my-roomname"
68-
async with aconnect_ws(f"http://localhost:{port}/{room_name}") as websocket, Provider(
69-
ydoc, Websocket(websocket, room_name)
68+
async with (
69+
aconnect_ws(f"http://localhost:{port}/{room_name}") as websocket,
70+
Provider(ydoc, Websocket(websocket, room_name)),
7071
):
7172
nb = stringify_source(json.loads((files_dir / "nb0.ipynb").read_text()))
7273
ynotebook.source = nb
@@ -85,8 +86,9 @@ async def test_ypy_yjs_1(yws_server, yjs_client):
8586
nb = stringify_source(json.loads((files_dir / "nb1.ipynb").read_text()))
8687
ynotebook.source = nb
8788
room_name = "my-roomname"
88-
async with aconnect_ws(f"http://localhost:{port}/{room_name}") as websocket, Provider(
89-
ydoc, Websocket(websocket, room_name)
89+
async with (
90+
aconnect_ws(f"http://localhost:{port}/{room_name}") as websocket,
91+
Provider(ydoc, Websocket(websocket, room_name)),
9092
):
9193
output_text = ynotebook.ycells[0]["outputs"][0]["text"]
9294
assert output_text.to_py() == "Hello,"

0 commit comments

Comments
 (0)