Skip to content

Commit 496af07

Browse files
phernandezclaude
andcommitted
fix: resolve pyright possibly-unbound errors in edit_note
Initialize entity_id and result before the try/except block and add assertion before the formatting section to help pyright prove result is always bound on all code paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent b5667f9 commit 496af07

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/basic_memory/mcp/tools/edit_note.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from basic_memory.mcp.project_context import get_project_client, add_project_metadata
99
from basic_memory.mcp.server import mcp
1010
from basic_memory.schemas.base import Entity
11+
from basic_memory.schemas.response import EntityResponse
1112
from basic_memory.utils import validate_project_path
1213

1314

@@ -25,12 +26,12 @@ def _parse_identifier_to_title_and_directory(identifier: str) -> tuple[str, str]
2526
"""
2627
cleaned = identifier
2728
if cleaned.startswith("memory://"):
28-
cleaned = cleaned[len("memory://"):]
29+
cleaned = cleaned[len("memory://") :]
2930

3031
if "/" in cleaned:
3132
last_slash = cleaned.rfind("/")
3233
directory = cleaned[:last_slash]
33-
title = cleaned[last_slash + 1:]
34+
title = cleaned[last_slash + 1 :]
3435
else:
3536
directory = ""
3637
title = cleaned
@@ -277,6 +278,8 @@ async def edit_note(
277278
knowledge_client = KnowledgeClient(client, active_project.external_id)
278279

279280
file_created = False
281+
entity_id = ""
282+
result: EntityResponse | None = None
280283

281284
# Try to resolve the entity; for append/prepend, create it if not found
282285
try:
@@ -325,9 +328,7 @@ async def edit_note(
325328
directory=directory,
326329
operation=operation,
327330
)
328-
result = await knowledge_client.create_entity(
329-
entity.model_dump(), fast=False
330-
)
331+
result = await knowledge_client.create_entity(entity.model_dump(), fast=False)
331332
file_created = True
332333
else:
333334
# find_replace/replace_section require existing content — re-raise
@@ -353,6 +354,8 @@ async def edit_note(
353354
result = await knowledge_client.patch_entity(entity_id, edit_data, fast=False)
354355

355356
# --- Format response ---
357+
# result is always set: either by create_entity (auto-create) or patch_entity (edit)
358+
assert result is not None
356359
if file_created:
357360
summary = [
358361
f"# Created note ({operation})",
@@ -379,9 +382,7 @@ async def edit_note(
379382
summary.append(f"operation: Added {lines_added} lines to end of note")
380383
elif operation == "prepend":
381384
lines_added = len(content.split("\n"))
382-
summary.append(
383-
f"operation: Added {lines_added} lines to beginning of note"
384-
)
385+
summary.append(f"operation: Added {lines_added} lines to beginning of note")
385386
elif operation == "find_replace":
386387
# For find_replace, we can't easily count replacements from here
387388
# since we don't have the original content, but the server handled it
@@ -448,5 +449,10 @@ async def edit_note(
448449
"error": str(e),
449450
}
450451
return _format_error_response(
451-
str(e), operation, identifier, find_text, effective_replacements, active_project.name
452+
str(e),
453+
operation,
454+
identifier,
455+
find_text,
456+
effective_replacements,
457+
active_project.name,
452458
)

0 commit comments

Comments
 (0)