Skip to content

Commit cd61589

Browse files
[pre-commit.ci] pre-commit autoupdate (#71)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 23.12.1 → 24.1.1](psf/black@23.12.1...24.1.1) - [github.com/astral-sh/ruff-pre-commit: v0.1.13 → v0.1.14](astral-sh/ruff-pre-commit@v0.1.13...v0.1.14) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 39924ba commit cd61589

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 23.12.1
3+
rev: 24.1.1
44
hooks:
55
- id: black
66

77
- repo: https://github.com/astral-sh/ruff-pre-commit
8-
rev: v0.1.13
8+
rev: v0.1.14
99
hooks:
1010
- id: ruff
1111
args: ["--fix"]

python/pycrdt/_pycrdt.pyi

+33
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,41 @@ class Doc:
66
def __init__(self, client_id: int | None) -> None:
77
"""Create a new document with an optional global client ID.
88
If no client ID is passed, a random one will be generated."""
9+
910
def client_id(self) -> int:
1011
"""Returns the document unique client identifier."""
12+
1113
def guid(self) -> int:
1214
"""Returns the document globally unique identifier."""
15+
1316
def create_transaction(self) -> Transaction:
1417
"""Create a document transaction."""
18+
1519
def get_or_insert_text(self, name: str) -> Text:
1620
"""Create a text root type on this document, or get an existing one."""
21+
1722
def get_or_insert_array(self, name: str) -> Array:
1823
"""Create an array root type on this document, or get an existing one."""
24+
1925
def get_or_insert_map(self, name: str) -> Map:
2026
"""Create a map root type on this document, or get an existing one."""
27+
2128
def get_state(self) -> bytes:
2229
"""Get the current document state."""
30+
2331
def get_update(self, state: bytes) -> bytes:
2432
"""Get the update from the given state to the current state."""
33+
2534
def apply_update(self, update: bytes) -> None:
2635
"""Apply the update to the document."""
36+
2737
def roots(self, txn: Transaction) -> dict[str, Text | Array | Map]:
2838
"""Get top-level (root) shared types available in current document."""
39+
2940
def observe(self, callback: Callable[[TransactionEvent], None]) -> int:
3041
"""Subscribes a callback to be called with the shared document change event.
3142
Returns a subscription ID that can be used to unsubscribe."""
43+
3244
def observe_subdocs(self, callback: Callable[[SubdocsEvent], None]) -> int:
3345
"""Subscribes a callback to be called with the shared document subdoc change event.
3446
Returns a subscription ID that can be used to unsubscribe."""
@@ -38,6 +50,7 @@ class Transaction:
3850

3951
def drop(self) -> None:
4052
"""Drop the transaction, effectively committing document changes."""
53+
4154
def commit(self) -> None:
4255
"""Commit the document changes."""
4356

@@ -66,16 +79,21 @@ class Text:
6679

6780
def len(self, txn: Transaction) -> int:
6881
"""Returns the number of characters visible in the current shared text."""
82+
6983
def insert(self, txn: Transaction, index: int, chunk: str) -> None:
7084
"""Inserts a `chunk` of text at a given `index`."""
85+
7186
def remove_range(self, txn: Transaction, index: int, len: int) -> None:
7287
"""Removes up to `len` characters from th current shared text, starting at
7388
given`index`."""
89+
7490
def get_string(self, txn: Transaction) -> str:
7591
"""Returns a text representation of the current shared text."""
92+
7693
def observe(self, callback: Callable[[TextEvent], None]) -> int:
7794
"""Subscribes a callback to be called with the shared text change event.
7895
Returns a subscription ID that can be used to unsubscribe."""
96+
7997
def unobserve(self, subscription_id: int) -> None:
8098
"""Unsubscribes previously subscribed event callback identified by given
8199
`subscription_id`."""
@@ -85,23 +103,31 @@ class Array:
85103

86104
def len(self, txn: Transaction) -> int:
87105
"""Returns the number of elements in the current array."""
106+
88107
def insert(self, txn: Transaction, index: int, value: Any) -> None:
89108
"""Inserts `value` at the given `index`."""
109+
90110
def move_to(self, txn: Transaction, source: int, target: int) -> None:
91111
"""Moves element found at `source` index into `target` index position.."""
112+
92113
def remove_range(self, txn: Transaction, index: int, len: int) -> None:
93114
"""Removes 'len' elements starting at provided `index`."""
115+
94116
def get(self, txn: Transaction, index: int) -> Any:
95117
"""Retrieves a value stored at a given `index`."""
118+
96119
def to_json(self, txn: Transaction) -> str:
97120
"""Returns a JSON representation of the current array."""
121+
98122
def observe(self, callback: Callable[[TextEvent], None]) -> int:
99123
"""Subscribes a callback to be called with the array change event.
100124
Returns a subscription ID that can be used to unsubscribe."""
125+
101126
def observe_deep(self, callback: Callable[[TextEvent], None]) -> int:
102127
"""Subscribes a callback to be called with the array change event
103128
and its nested elements.
104129
Returns a subscription ID that can be used to unsubscribe."""
130+
105131
def unobserve(self, subscription_id: int) -> None:
106132
"""Unsubscribes previously subscribed event callback identified by given
107133
`subscription_id`."""
@@ -111,21 +137,28 @@ class Map:
111137

112138
def len(self, txn: Transaction) -> int:
113139
"""Returns a number of characters visible in a current text data structure."""
140+
114141
def insert(self, txn: Transaction, key: str, value: Any) -> None:
115142
"""Inserts `value` at the given `key`."""
143+
116144
def remove(self, txn: Transaction, key: str) -> None:
117145
"""Removes the `key` entry."""
146+
118147
def get(self, txn: Transaction, key: str) -> Any:
119148
"""Retrieves a value stored under a given `key`."""
149+
120150
def to_json(self, txn: Transaction) -> str:
121151
"""Returns a JSON representation of the current map."""
152+
122153
def observe(self, callback: Callable[[TextEvent], None]) -> int:
123154
"""Subscribes a callback to be called with the map change event.
124155
Returns a subscription ID that can be used to unsubscribe."""
156+
125157
def observe_deep(self, callback: Callable[[TextEvent], None]) -> int:
126158
"""Subscribes a callback to be called with the map change event
127159
and its nested elements.
128160
Returns a subscription ID that can be used to unsubscribe."""
161+
129162
def unobserve(self, subscription_id: int) -> None:
130163
"""Unsubscribes previously subscribed event callback identified by given
131164
`subscription_id`."""

python/pycrdt/base.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,13 @@ def __init__(
6363
self._integrated = None
6464

6565
@abstractmethod
66-
def to_py(self) -> Any:
67-
...
66+
def to_py(self) -> Any: ...
6867

6968
@abstractmethod
70-
def _get_or_insert(self, name: str, doc: Doc) -> Any:
71-
...
69+
def _get_or_insert(self, name: str, doc: Doc) -> Any: ...
7270

7371
@abstractmethod
74-
def _init(self, value: Any | None) -> None:
75-
...
72+
def _init(self, value: Any | None) -> None: ...
7673

7774
def _forbid_read_transaction(self, txn: Transaction):
7875
if isinstance(txn, ReadTransaction):

python/pycrdt/doc.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ def _roots(self) -> dict[str, BaseType]:
8787
with self.transaction() as txn:
8888
assert txn._txn is not None
8989
return {
90-
key: None
91-
if val is None
92-
else cast(Type[BaseType], base_types[type(val)])(
93-
_integrated=val, _doc=self
90+
key: (
91+
None
92+
if val is None
93+
else cast(Type[BaseType], base_types[type(val)])(
94+
_integrated=val, _doc=self
95+
)
9496
)
9597
for key, val in self._doc.roots(txn._txn).items()
9698
}

0 commit comments

Comments
 (0)