From 87c0d1939ab4b60471bf94cf25c82d00b0954465 Mon Sep 17 00:00:00 2001 From: Auguste Baum <52001167+augustebaum@users.noreply.github.com> Date: Fri, 17 Jan 2025 12:02:50 +0100 Subject: [PATCH] chore: Harmonize `message` to `note` in notes-related methods (#1143) --- skore/src/skore/item/item_repository.py | 14 +++++++------- skore/src/skore/project/project.py | 16 +++++++--------- skore/src/skore/ui/project_routes.py | 2 +- skore/tests/unit/project/test_notes.py | 14 +++++++------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/skore/src/skore/item/item_repository.py b/skore/src/skore/item/item_repository.py index b00d481ca..76369477f 100644 --- a/skore/src/skore/item/item_repository.py +++ b/skore/src/skore/item/item_repository.py @@ -154,7 +154,7 @@ def keys(self) -> list[str]: """ return list(self.storage.keys()) - def set_item_note(self, key: str, message: str, *, version=-1): + def set_item_note(self, key: str, note: str, *, version=-1): """Attach a note to key ``key``. Parameters @@ -162,8 +162,8 @@ def set_item_note(self, key: str, message: str, *, version=-1): key : str The key of the item to annotate. May be qualified with a version number through the ``version`` argument. - message : str - The message to be attached. + note : str + The note to be attached. version : int, default=-1 The version of the key to annotate. Default is the latest version. @@ -172,16 +172,16 @@ def set_item_note(self, key: str, message: str, *, version=-1): KeyError If the ``(key, version)`` couple does not exist. TypeError - If ``key`` or ``message`` is not a string. + If ``key`` or ``note`` is not a string. """ if not isinstance(key, str): raise TypeError(f"Key should be a string; got {type(key)}") - if not isinstance(message, str): - raise TypeError(f"Message should be a string; got {type(message)}") + if not isinstance(note, str): + raise TypeError(f"Note should be a string; got {type(note)}") try: old = self.storage[key] - old[version]["item"]["note"] = message + old[version]["item"]["note"] = note self.storage[key] = old except IndexError as e: raise KeyError((key, version)) from e diff --git a/skore/src/skore/project/project.py b/skore/src/skore/project/project.py index c9e94c171..df65bb279 100644 --- a/skore/src/skore/project/project.py +++ b/skore/src/skore/project/project.py @@ -272,7 +272,7 @@ def list_view_keys(self) -> list[str]: """ return self.view_repository.keys() - def set_note(self, key: str, message: str, *, version=-1): + def set_note(self, key: str, note: str, *, version=-1): """Attach a note to key ``key``. Parameters @@ -280,8 +280,8 @@ def set_note(self, key: str, message: str, *, version=-1): key : str The key of the item to annotate. May be qualified with a version number through the ``version`` argument. - message : str - The message to be attached. + note : str + The note to be attached. version : int, default=-1 The version of the key to annotate. Default is the latest version. @@ -290,19 +290,17 @@ def set_note(self, key: str, message: str, *, version=-1): KeyError If the ``(key, version)`` couple does not exist. TypeError - If ``key`` or ``message`` is not a string. + If ``key`` or ``note`` is not a string. Examples -------- # Annotate latest version of key "key" - >>> project.set_note("key", "message") # doctest: +SKIP + >>> project.set_note("key", "note") # doctest: +SKIP # Annotate first version of key "key" - >>> project.set_note("key", "message", version=0) # doctest: +SKIP + >>> project.set_note("key", "note", version=0) # doctest: +SKIP """ - return self.item_repository.set_item_note( - key=key, message=message, version=version - ) + return self.item_repository.set_item_note(key=key, note=note, version=version) def get_note(self, key: str, *, version=-1) -> Union[str, None]: """Retrieve a note previously attached to key ``key``. diff --git a/skore/src/skore/ui/project_routes.py b/skore/src/skore/ui/project_routes.py index 60e3c3d48..94de0bbae 100644 --- a/skore/src/skore/ui/project_routes.py +++ b/skore/src/skore/ui/project_routes.py @@ -136,5 +136,5 @@ class NotePayload: async def set_note(request: Request, payload: NotePayload): """Add a note to the given item.""" project = request.app.state.project - project.set_note(key=payload.key, message=payload.message, version=payload.version) + project.set_note(key=payload.key, note=payload.message, version=payload.version) return __project_as_serializable(project) diff --git a/skore/tests/unit/project/test_notes.py b/skore/tests/unit/project/test_notes.py index e2b3929dd..663153650 100644 --- a/skore/tests/unit/project/test_notes.py +++ b/skore/tests/unit/project/test_notes.py @@ -15,18 +15,18 @@ def test_set_note(self, project_fixture, request): project = request.getfixturevalue(project_fixture) project.put("key", "hello") - project.set_note("key", "message") - assert project.get_note("key") == "message" + project.set_note("key", "note") + assert project.get_note("key") == "note" def test_set_note_version(self, project_fixture, request): - """By default, `set_note` only attaches a message to the latest version + """By default, `set_note` only attaches a note to the latest version of a key.""" project = request.getfixturevalue(project_fixture) project.put("key", "hello") project.put("key", "goodbye") - project.set_note("key", "message") - assert project.get_note("key", version=-1) == "message" + project.set_note("key", "note") + assert project.get_note("key", version=-1) == "note" assert project.get_note("key", version=0) is None def test_set_note_no_key(self, project_fixture, request): @@ -41,7 +41,7 @@ def test_set_note_no_key(self, project_fixture, request): project.set_note("key", "hello", version=10) def test_set_note_not_strings(self, project_fixture, request): - """If key or message is not a string, raise a TypeError.""" + """If key or note is not a string, raise a TypeError.""" project = request.getfixturevalue(project_fixture) with pytest.raises(TypeError): @@ -54,7 +54,7 @@ def test_delete_note(self, project_fixture, request): project = request.getfixturevalue(project_fixture) project.put("key", "hello") - project.set_note("key", "message") + project.set_note("key", "note") project.delete_note("key") assert project.get_note("key") is None