From 5f6438ecf3c19c43f2205c8a4645ae6531551863 Mon Sep 17 00:00:00 2001 From: Andrew Yim Date: Tue, 28 Apr 2026 07:50:03 +0900 Subject: [PATCH] fix(notion-search): polish expand_query (warn on shape error, lint fixes) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code review polish: - Add stderr warning for the fourth failure path (LLM returned valid JSON but it's not a list-of-strings). Previously this fell back silently, making debugging harder when Haiku produces unexpected shapes. - Drop unused f-string prefixes from two warnings (no interpolation). - Type hint: Callable[..., str] = None → Optional[Callable[..., str]] = None for strict type-checker compatibility. 12/12 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../31-notion-organizer/code/scripts/notion_search.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custom-skills/31-notion-organizer/code/scripts/notion_search.py b/custom-skills/31-notion-organizer/code/scripts/notion_search.py index 57b7240..cf40985 100644 --- a/custom-skills/31-notion-organizer/code/scripts/notion_search.py +++ b/custom-skills/31-notion-organizer/code/scripts/notion_search.py @@ -11,7 +11,7 @@ from __future__ import annotations import json import re import sys -from typing import Callable, List +from typing import Callable, List, Optional from _search_llm import call_claude as default_llm_caller @@ -32,7 +32,7 @@ Return ONLY a JSON array of strings, no prose. Example: def expand_query( query: str, *, - llm_caller: Callable[..., str] = None, + llm_caller: Optional[Callable[..., str]] = None, max_variants: int = 5, ) -> List[str]: """Expand a query into related variants. Returns [query] on any failure.""" @@ -51,18 +51,20 @@ def expand_query( # Be permissive: extract the first JSON array from the response. match = re.search(r'\[.*\]', response, re.DOTALL) if not match: - print(f"Warning: query expansion returned no JSON array; using original query only", + print("Warning: query expansion returned no JSON array; using original query only", file=sys.stderr) return [query] try: variants = json.loads(match.group(0)) except json.JSONDecodeError: - print(f"Warning: query expansion returned invalid JSON; using original query only", + print("Warning: query expansion returned invalid JSON; using original query only", file=sys.stderr) return [query] if not isinstance(variants, list) or not all(isinstance(v, str) for v in variants): + print("Warning: query expansion returned non-string-list shape; using original query only", + file=sys.stderr) return [query] # Always include the original query first; dedupe; cap at max_variants.