From 6ec77091b6c77080cd03fef0efbf09e451544ee7 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Tue, 14 Jul 2026 09:58:43 +0200 Subject: [PATCH] style(librarian): apply ruff autofixes to client and tools Mechanical Optional[X] -> X | None and f-string cleanups so subsequent librarian changes lint clean against the dirty baseline. Co-Authored-By: Claude Fable 5 --- src/agents/librarian/client.py | 58 +++++++++++++++++----------------- src/agents/librarian/tools.py | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/agents/librarian/client.py b/src/agents/librarian/client.py index 4ff9910..c8a8f39 100644 --- a/src/agents/librarian/client.py +++ b/src/agents/librarian/client.py @@ -7,7 +7,7 @@ Provides async methods for all relevant library-desk endpoints: - Vector search - Knowledge graph queries """ -from typing import Any, Optional +from typing import Any import httpx from pydantic import BaseModel, Field @@ -28,11 +28,11 @@ class WikiPage(BaseModel): id: int path: str title: str - description: Optional[str] = None - content: Optional[str] = None + description: str | None = None + content: str | None = None tags: list[str] = Field(default_factory=list) - created_at: Optional[str] = None - updated_at: Optional[str] = None + created_at: str | None = None + updated_at: str | None = None class WikiSearchResult(BaseModel): @@ -40,8 +40,8 @@ class WikiSearchResult(BaseModel): id: int path: str title: str - description: Optional[str] = None - locale: Optional[str] = None + description: str | None = None + locale: str | None = None class VectorSearchResult(BaseModel): @@ -59,9 +59,9 @@ class HybridSearchResult(BaseModel): source: str # "vector", "graph", "web" title: str content: str - url: Optional[str] = None + url: str | None = None score: float - page_id: Optional[int] = None + page_id: int | None = None metadata: dict[str, Any] = Field(default_factory=dict) @@ -72,7 +72,7 @@ class HybridRAGResponse(BaseModel): synonyms: list[str] = Field(default_factory=list) related_dossiers: list[str] = Field(default_factory=list) formatted_context: str = "" - search_id: Optional[str] = None + search_id: str | None = None timing: dict[str, float] = Field(default_factory=dict) @@ -105,7 +105,7 @@ class WebSearchResult(BaseModel): content: str = "" # Full extracted text via Trafilatura snippet: str = "" # Original search engine snippet source: str = "" # Domain name - published_date: Optional[str] = None + published_date: str | None = None class WebSearchResponse(BaseModel): @@ -121,13 +121,13 @@ class WebSearchResponse(BaseModel): class ContentExtractionResult(BaseModel): """Result from content extraction.""" url: str - title: Optional[str] = None + title: str | None = None content: str = "" - author: Optional[str] = None - date: Optional[str] = None - language: Optional[str] = None + author: str | None = None + date: str | None = None + language: str | None = None success: bool = True - error: Optional[str] = None + error: str | None = None class BatchExtractionResponse(BaseModel): @@ -151,7 +151,7 @@ class SmartCreateResponse(BaseModel): page: WikiPage research_summary: ResearchSummary = Field(default_factory=ResearchSummary) sources_used: int = 0 - search_id: Optional[str] = None + search_id: str | None = None entity_linking: EntityLinking = Field(default_factory=EntityLinking) @@ -170,8 +170,8 @@ class LibraryDeskClient: def __init__( self, - base_url: Optional[str] = None, - api_key: Optional[str] = None, + base_url: str | None = None, + api_key: str | None = None, timeout: int = 60, ): """ @@ -185,7 +185,7 @@ class LibraryDeskClient: self.base_url = base_url or str(config.LIBRARY_DESK_HOST) self.api_key = api_key or config.LIBRARY_DESK_API_KEY self.timeout = timeout - self._client: Optional[httpx.AsyncClient] = None + self._client: httpx.AsyncClient | None = None async def __aenter__(self) -> "LibraryDeskClient": """Create HTTP client on context entry.""" @@ -371,7 +371,7 @@ class LibraryDeskClient: async def list_wiki_pages( self, user: str | None = None, - tag: Optional[str] = None, + tag: str | None = None, limit: int = 50, ) -> list[WikiPage]: """ @@ -405,7 +405,7 @@ class LibraryDeskClient: content: str, user: str | None = None, description: str = "", - tags: Optional[list[str]] = None, + tags: list[str] | None = None, ) -> WikiPage: """ Create a new wiki page. @@ -444,10 +444,10 @@ class LibraryDeskClient: self, page_id: int, user: str | None = None, - content: Optional[str] = None, - title: Optional[str] = None, - tags: Optional[list[str]] = None, - description: Optional[str] = None, + content: str | None = None, + title: str | None = None, + tags: list[str] | None = None, + description: str | None = None, ) -> WikiPage: """ Update an existing wiki page. @@ -500,7 +500,7 @@ class LibraryDeskClient: topic: str, tags: list[str], user: str | None = None, - path: Optional[str] = None, + path: str | None = None, include_web_research: bool = True, include_wiki_search: bool = True, ) -> SmartCreateResponse: @@ -636,7 +636,7 @@ class LibraryDeskClient: self, cypher_query: str, user: str | None = None, - parameters: Optional[dict[str, Any]] = None, + parameters: dict[str, Any] | None = None, ) -> list[dict[str, Any]]: """ Execute a Cypher query on the knowledge graph. @@ -670,7 +670,7 @@ class LibraryDeskClient: async def list_graph_nodes( self, user: str | None = None, - node_type: Optional[str] = None, + node_type: str | None = None, limit: int = 100, ) -> list[GraphNode]: """ diff --git a/src/agents/librarian/tools.py b/src/agents/librarian/tools.py index 87cf300..9bc84ba 100644 --- a/src/agents/librarian/tools.py +++ b/src/agents/librarian/tools.py @@ -635,7 +635,7 @@ async def read_urls_batch( ) output_parts = [ - f"## Batch Content Extraction", + "## Batch Content Extraction", f"*Extracted {response.successful}/{response.total_urls} URLs in {response.extraction_time_ms}ms*\n", ]