Skip to content

Commit 2ccb9bc

Browse files
committed
refactor(cli): unify _resolve_source_for_delete return type to str
Mixed return type (str for UUID fast-path, source object otherwise) was a maintenance hazard. Now always returns the ID string, removing the isinstance check at the call site. Also fixes stale docstring that claimed live list validation for all paths.
1 parent 163d4ca commit 2ccb9bc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/notebooklm/cli/source.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ def _looks_like_full_source_id(source_id: str) -> bool:
8787
)
8888

8989

90-
async def _resolve_source_for_delete(client, notebook_id: str, source_id: str):
91-
"""Resolve a source for delete, always validating against the live source list."""
90+
async def _resolve_source_for_delete(client, notebook_id: str, source_id: str) -> str:
91+
"""Resolve a source ID for delete, returning the full source ID string.
92+
93+
Canonical UUIDs take a fast path and skip the live source list lookup.
94+
Partial IDs are resolved against the live list.
95+
"""
9296
source_id = validate_id(source_id, "source")
9397
if _looks_like_full_source_id(source_id):
9498
return source_id
@@ -100,7 +104,7 @@ async def _resolve_source_for_delete(client, notebook_id: str, source_id: str):
100104
if matches[0].id != source_id:
101105
title = matches[0].title or "(untitled)"
102106
console.print(f"[dim]Matched: {matches[0].id[:12]}... ({title})[/dim]")
103-
return matches[0]
107+
return matches[0].id
104108

105109
if len(matches) > 1:
106110
raise _build_id_ambiguity_error(source_id, matches)
@@ -359,10 +363,7 @@ def source_delete(ctx, source_id, notebook_id, yes, client_auth):
359363
async def _run():
360364
async with NotebookLMClient(client_auth) as client:
361365
nb_id_resolved = await resolve_notebook_id(client, nb_id)
362-
resolved_source = await _resolve_source_for_delete(client, nb_id_resolved, source_id)
363-
resolved_id = (
364-
resolved_source if isinstance(resolved_source, str) else resolved_source.id
365-
)
366+
resolved_id = await _resolve_source_for_delete(client, nb_id_resolved, source_id)
366367

367368
if not yes and not click.confirm(f"Delete source {resolved_id}?"):
368369
return

0 commit comments

Comments
 (0)