From 8ffa3a5c966ef9a5ac6049640ef16b2d6b62d83a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 17:05:41 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.15.21 → v0.16.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.21...v0.16.3) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b98f88e..5096f35 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.21 + rev: v0.16.3 hooks: - id: ruff args: [--fix, --show-fixes] From 11921e9876c1be9113bb4eaac8741819c223c10c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 17:05:49 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/cocat/api.py | 8 ++++---- src/cocat/app/db.py | 3 +-- src/cocat/catalogue.py | 4 ++-- src/cocat/db.py | 40 +++++++++++++++------------------------- src/cocat/event.py | 6 +++--- src/cocat/votable.py | 4 ++-- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/cocat/api.py b/src/cocat/api.py index 58e2cd3..5a8dde1 100644 --- a/src/cocat/api.py +++ b/src/cocat/api.py @@ -1,9 +1,9 @@ import atexit -from collections.abc import Iterable +from collections.abc import Iterable, Sequence from contextlib import ExitStack from datetime import datetime from pathlib import Path -from typing import Any, Sequence +from typing import Any from urllib.parse import urlparse from uuid import UUID @@ -207,8 +207,8 @@ def create_catalogue( def create_event( *, - start: datetime | int | float | str, - stop: datetime | int | float | str, + start: datetime | float | str, + stop: datetime | float | str, author: str, uuid: UUID | str | bytes | bytearray | None = None, tags: list[str] | None = None, diff --git a/src/cocat/app/db.py b/src/cocat/app/db.py index 081fe95..b3ef07b 100644 --- a/src/cocat/app/db.py +++ b/src/cocat/app/db.py @@ -1,6 +1,5 @@ -from collections.abc import AsyncGenerator, Callable +from collections.abc import AsyncGenerator, Awaitable, Callable from dataclasses import dataclass -from typing import Awaitable from anyio import Lock, Path from fastapi import Depends diff --git a/src/cocat/catalogue.py b/src/cocat/catalogue.py index 16fa198..45aff0d 100644 --- a/src/cocat/catalogue.py +++ b/src/cocat/catalogue.py @@ -34,7 +34,7 @@ def _check_deleted(self): if self._uuid not in self._db._catalogue_maps: raise RuntimeError("Catalogue has been deleted") - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: self._check_deleted() if not isinstance(other, Catalogue): return NotImplemented @@ -135,7 +135,7 @@ def to_dict(self, event_as_uuid: bool = False) -> dict[str, Any]: self._check_deleted() dct = self._map.to_py() assert dct is not None - dct["tags"] = list(sorted(dct["tags"].keys())) + dct["tags"] = sorted(dct["tags"].keys()) dct["events"] = [ uuid if event_as_uuid else Event._from_uuid(uuid, self._db).to_dict() for uuid in sorted(dct["events"].keys()) diff --git a/src/cocat/db.py b/src/cocat/db.py index b9a1a8b..b96cc96 100644 --- a/src/cocat/db.py +++ b/src/cocat/db.py @@ -70,7 +70,7 @@ def __repr__(self) -> str: return capture.get() def _callback( - self, callback: Callable[..., None], origin: "DB" | None, *args: Any + self, callback: Callable[..., None], origin: DB | None, *args: Any ) -> None: if origin is not self: callback(*args) @@ -79,7 +79,7 @@ def transaction(self) -> Transaction: return self._doc.transaction(self) @classmethod - def from_dict(cls, db_dict: dict[str, Any], doc: Doc | None = None) -> "DB": + def from_dict(cls, db_dict: dict[str, Any], doc: Doc | None = None) -> DB: """ Creates a database from a dictionary. @@ -100,7 +100,7 @@ def from_dict(cls, db_dict: dict[str, Any], doc: Doc | None = None) -> "DB": return db @classmethod - def from_json(cls, data: str, doc: Doc | None = None) -> "DB": + def from_json(cls, data: str, doc: Doc | None = None) -> DB: """ Creates a database from a JSON string. @@ -201,9 +201,7 @@ def _catalogues_changed( for key, val in keys.items(): if val["action"] == "delete": removed.add(key) - elif val["action"] == "add": - added[key] = val["newValue"] - elif val["action"] == "update": + elif val["action"] == "add" or val["action"] == "update": added[key] = val["newValue"] if removed: callbacks = self._catalogue_change_callbacks[uuid][ @@ -261,9 +259,7 @@ def _events_changed(self, events: list[MapEvent], transaction: Transaction) -> N for key, val in keys.items(): if val["action"] == "delete": removed.add(key) - elif val["action"] == "add": - added[key] = val["newValue"] - elif val["action"] == "update": + elif val["action"] == "add" or val["action"] == "update": added[key] = val["newValue"] if removed: callbacks = self._event_change_callbacks[uuid][f"remove_{name}"] @@ -344,8 +340,8 @@ def create_catalogue( def create_event( self, *, - start: datetime | int | float | str, - stop: datetime | int | float | str, + start: datetime | float | str, + stop: datetime | float | str, author: str, uuid: UUID | str | bytes | bytearray | None = None, tags: list[str] | None = None, @@ -444,9 +440,7 @@ def get_event(self, uuid: UUID | str) -> Event: except KeyError: raise RuntimeError(f"No event found with UUID: {uuid}") - def _handle_sync_message( - self, message: bytes, db: "DB", init: bool = False - ) -> None: + def _handle_sync_message(self, message: bytes, db: DB, init: bool = False) -> None: if init: _message = create_sync_message(self._doc) db._handle_sync_message(_message, self) @@ -464,7 +458,7 @@ def _handle_sync_message( ): # pragma: nocover raise - def sync(self, db: "DB") -> None: + def sync(self, db: DB) -> None: """ Keeps the database in sync with another database. Mostly used for tests. @@ -487,17 +481,13 @@ def to_dict(self) -> dict[str, Any]: The database as a dictionary. """ db_dict = { - "events": list( - sorted( - [event.to_dict() for event in self.events], - key=lambda event: event["uuid"], - ) + "events": sorted( + [event.to_dict() for event in self.events], + key=lambda event: event["uuid"], ), - "catalogues": list( - sorted( - [catalogue.to_dict(True) for catalogue in self.catalogues], - key=lambda catalogue: catalogue["uuid"], - ) + "catalogues": sorted( + [catalogue.to_dict(True) for catalogue in self.catalogues], + key=lambda catalogue: catalogue["uuid"], ), } events = db_dict["events"] diff --git a/src/cocat/event.py b/src/cocat/event.py index 31e811d..60432fd 100644 --- a/src/cocat/event.py +++ b/src/cocat/event.py @@ -31,7 +31,7 @@ def _check_deleted(self): if self._uuid not in self._db._event_maps: raise RuntimeError("Event has been deleted") - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: self._check_deleted() if not isinstance(other, Event): return NotImplemented @@ -131,8 +131,8 @@ def to_dict(self) -> dict[str, Any]: self._check_deleted() dct = self._map.to_py() assert dct is not None - dct["tags"] = list(sorted(dct["tags"].keys())) - dct["products"] = list(sorted(dct["products"].keys())) + dct["tags"] = sorted(dct["tags"].keys()) + dct["products"] = sorted(dct["products"].keys()) dct["attributes"] = dict(sorted(dct["attributes"].items())) return {key: dct[key] for key in EventModel.model_fields.keys()} diff --git a/src/cocat/votable.py b/src/cocat/votable.py index 83510bd..a2a11bf 100644 --- a/src/cocat/votable.py +++ b/src/cocat/votable.py @@ -263,8 +263,8 @@ def import_votable( "events": [], } - has_author_field = any(f[1] == "author" for f in fields_vs_index.keys()) - has_uuid_field = any(f[1] == "uuid" for f in fields_vs_index.keys()) + has_author_field = any(f[1] == "author" for f in fields_vs_index) + has_uuid_field = any(f[1] == "uuid" for f in fields_vs_index) for el in table.array: event: dict[str, Any] = {"attributes": {}}