From 6ada97bb0bb483ea2bb58a8c21ff25c28cdf583c Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 26 Aug 2026 15:03:40 -0400 Subject: [PATCH] fix(rules): resolve the Rule forward ref for ruff and readers (#3030) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit F821: the quoted `"Rule"` in semantic_search_rules' return annotation evaluates fine at runtime — a string inside a subscript is a value, not a name lookup — but it points at nothing a reader or a type checker can follow, which is what ruff is objecting to and it is right to. A TYPE_CHECKING import resolves it at zero runtime cost, while the real import stays inside the function so this module still does not pull in the rulebook models. Placed after the import block, where isort wants the guard. Co-Authored-By: Claude Opus 5 (1M context) --- src/scribe/services/embeddings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/scribe/services/embeddings.py b/src/scribe/services/embeddings.py index 49255de..f5f464a 100644 --- a/src/scribe/services/embeddings.py +++ b/src/scribe/services/embeddings.py @@ -16,6 +16,8 @@ import os from collections.abc import Sequence +from typing import TYPE_CHECKING + from sqlalchemy import delete, or_, select from scribe.models import async_session @@ -23,6 +25,9 @@ from scribe.models.embedding import NoteEmbedding, RuleEmbedding from scribe.models.note import Note from scribe.services.access import notes_visibility_clause +if TYPE_CHECKING: # resolves the Rule forward ref without importing at runtime + from scribe.models.rulebook import Rule + logger = logging.getLogger(__name__) # Minimum cosine similarity to include a note in context results.