Skip to content

Commit

Permalink
chore: Harmonize message to note in notes-related methods (probab…
Browse files Browse the repository at this point in the history
  • Loading branch information
augustebaum authored and glemaitre committed Jan 17, 2025
1 parent c8eb0a4 commit 87c0d19
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
14 changes: 7 additions & 7 deletions skore/src/skore/item/item_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ 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
----------
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.
Expand All @@ -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
Expand Down
16 changes: 7 additions & 9 deletions skore/src/skore/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ 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
----------
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.
Expand All @@ -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``.
Expand Down
2 changes: 1 addition & 1 deletion skore/src/skore/ui/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 7 additions & 7 deletions skore/tests/unit/project/test_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit 87c0d19

Please sign in to comment.