Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #71

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.1.14
hooks:
- id: ruff
args: ["--fix"]
33 changes: 33 additions & 0 deletions python/pycrdt/_pycrdt.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,41 @@ class Doc:
def __init__(self, client_id: int | None) -> None:
"""Create a new document with an optional global client ID.
If no client ID is passed, a random one will be generated."""

def client_id(self) -> int:
"""Returns the document unique client identifier."""

def guid(self) -> int:
"""Returns the document globally unique identifier."""

def create_transaction(self) -> Transaction:
"""Create a document transaction."""

def get_or_insert_text(self, name: str) -> Text:
"""Create a text root type on this document, or get an existing one."""

def get_or_insert_array(self, name: str) -> Array:
"""Create an array root type on this document, or get an existing one."""

def get_or_insert_map(self, name: str) -> Map:
"""Create a map root type on this document, or get an existing one."""

def get_state(self) -> bytes:
"""Get the current document state."""

def get_update(self, state: bytes) -> bytes:
"""Get the update from the given state to the current state."""

def apply_update(self, update: bytes) -> None:
"""Apply the update to the document."""

def roots(self, txn: Transaction) -> dict[str, Text | Array | Map]:
"""Get top-level (root) shared types available in current document."""

def observe(self, callback: Callable[[TransactionEvent], None]) -> int:
"""Subscribes a callback to be called with the shared document change event.
Returns a subscription ID that can be used to unsubscribe."""

def observe_subdocs(self, callback: Callable[[SubdocsEvent], None]) -> int:
"""Subscribes a callback to be called with the shared document subdoc change event.
Returns a subscription ID that can be used to unsubscribe."""
Expand All @@ -38,6 +50,7 @@ class Transaction:

def drop(self) -> None:
"""Drop the transaction, effectively committing document changes."""

def commit(self) -> None:
"""Commit the document changes."""

Expand Down Expand Up @@ -66,16 +79,21 @@ class Text:

def len(self, txn: Transaction) -> int:
"""Returns the number of characters visible in the current shared text."""

def insert(self, txn: Transaction, index: int, chunk: str) -> None:
"""Inserts a `chunk` of text at a given `index`."""

def remove_range(self, txn: Transaction, index: int, len: int) -> None:
"""Removes up to `len` characters from th current shared text, starting at
given`index`."""

def get_string(self, txn: Transaction) -> str:
"""Returns a text representation of the current shared text."""

def observe(self, callback: Callable[[TextEvent], None]) -> int:
"""Subscribes a callback to be called with the shared text change event.
Returns a subscription ID that can be used to unsubscribe."""

def unobserve(self, subscription_id: int) -> None:
"""Unsubscribes previously subscribed event callback identified by given
`subscription_id`."""
Expand All @@ -85,23 +103,31 @@ class Array:

def len(self, txn: Transaction) -> int:
"""Returns the number of elements in the current array."""

def insert(self, txn: Transaction, index: int, value: Any) -> None:
"""Inserts `value` at the given `index`."""

def move_to(self, txn: Transaction, source: int, target: int) -> None:
"""Moves element found at `source` index into `target` index position.."""

def remove_range(self, txn: Transaction, index: int, len: int) -> None:
"""Removes 'len' elements starting at provided `index`."""

def get(self, txn: Transaction, index: int) -> Any:
"""Retrieves a value stored at a given `index`."""

def to_json(self, txn: Transaction) -> str:
"""Returns a JSON representation of the current array."""

def observe(self, callback: Callable[[TextEvent], None]) -> int:
"""Subscribes a callback to be called with the array change event.
Returns a subscription ID that can be used to unsubscribe."""

def observe_deep(self, callback: Callable[[TextEvent], None]) -> int:
"""Subscribes a callback to be called with the array change event
and its nested elements.
Returns a subscription ID that can be used to unsubscribe."""

def unobserve(self, subscription_id: int) -> None:
"""Unsubscribes previously subscribed event callback identified by given
`subscription_id`."""
Expand All @@ -111,21 +137,28 @@ class Map:

def len(self, txn: Transaction) -> int:
"""Returns a number of characters visible in a current text data structure."""

def insert(self, txn: Transaction, key: str, value: Any) -> None:
"""Inserts `value` at the given `key`."""

def remove(self, txn: Transaction, key: str) -> None:
"""Removes the `key` entry."""

def get(self, txn: Transaction, key: str) -> Any:
"""Retrieves a value stored under a given `key`."""

def to_json(self, txn: Transaction) -> str:
"""Returns a JSON representation of the current map."""

def observe(self, callback: Callable[[TextEvent], None]) -> int:
"""Subscribes a callback to be called with the map change event.
Returns a subscription ID that can be used to unsubscribe."""

def observe_deep(self, callback: Callable[[TextEvent], None]) -> int:
"""Subscribes a callback to be called with the map change event
and its nested elements.
Returns a subscription ID that can be used to unsubscribe."""

def unobserve(self, subscription_id: int) -> None:
"""Unsubscribes previously subscribed event callback identified by given
`subscription_id`."""
9 changes: 3 additions & 6 deletions python/pycrdt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,13 @@ def __init__(
self._integrated = None

@abstractmethod
def to_py(self) -> Any:
...
def to_py(self) -> Any: ...

@abstractmethod
def _get_or_insert(self, name: str, doc: Doc) -> Any:
...
def _get_or_insert(self, name: str, doc: Doc) -> Any: ...

@abstractmethod
def _init(self, value: Any | None) -> None:
...
def _init(self, value: Any | None) -> None: ...

def _forbid_read_transaction(self, txn: Transaction):
if isinstance(txn, ReadTransaction):
Expand Down
10 changes: 6 additions & 4 deletions python/pycrdt/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ def _roots(self) -> dict[str, BaseType]:
with self.transaction() as txn:
assert txn._txn is not None
return {
key: None
if val is None
else cast(Type[BaseType], base_types[type(val)])(
_integrated=val, _doc=self
key: (
None
if val is None
else cast(Type[BaseType], base_types[type(val)])(
_integrated=val, _doc=self
)
)
for key, val in self._doc.roots(txn._txn).items()
}
Expand Down
Loading