From bd801f49648db3c45bce4dc7f35d0f70411c6a49 Mon Sep 17 00:00:00 2001 From: adavyas Date: Tue, 7 Apr 2026 12:33:34 -0400 Subject: [PATCH] Fix basedpyright regressions for custom instructions --- src/config.py | 6 ++---- src/schemas/configuration.py | 10 ++++------ tests/routes/test_sessions.py | 3 ++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/config.py b/src/config.py index 6b8969d5..e98eab32 100644 --- a/src/config.py +++ b/src/config.py @@ -285,7 +285,7 @@ class DeriverSettings(BackupLLMSettingsMixin, HonchoSettings): if self.MAX_CUSTOM_INSTRUCTIONS_TOKENS is None: raise ValueError( "No value configured for DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS. " - "Set [deriver].MAX_CUSTOM_INSTRUCTIONS_TOKENS in config.toml." + + "Set [deriver].MAX_CUSTOM_INSTRUCTIONS_TOKENS in config.toml." ) return self.MAX_CUSTOM_INSTRUCTIONS_TOKENS @@ -301,9 +301,7 @@ class DeriverSettings(BackupLLMSettingsMixin, HonchoSettings): and self.MAX_CUSTOM_INSTRUCTIONS_TOKENS > self.MAX_INPUT_TOKENS ): raise ValueError( - "MAX_CUSTOM_INSTRUCTIONS_TOKENS " - f"({self.MAX_CUSTOM_INSTRUCTIONS_TOKENS}) cannot exceed " - f"max deriver input tokens ({self.MAX_INPUT_TOKENS})" + f"MAX_CUSTOM_INSTRUCTIONS_TOKENS ({self.MAX_CUSTOM_INSTRUCTIONS_TOKENS}) cannot exceed max deriver input tokens ({self.MAX_INPUT_TOKENS})" ) return self diff --git a/src/schemas/configuration.py b/src/schemas/configuration.py index 80993d23..fd24a7d8 100644 --- a/src/schemas/configuration.py +++ b/src/schemas/configuration.py @@ -5,7 +5,7 @@ the fully-resolved variants used at runtime. """ from enum import Enum -from typing import Any, Self, cast +from typing import Any, ClassVar, Self, cast import tiktoken from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator @@ -32,9 +32,7 @@ def _validate_custom_instructions_budget(value: str | None) -> str | None: token_limit = settings.DERIVER.effective_max_custom_instructions_tokens if token_count > token_limit: raise ValueError( - "reasoning.custom_instructions uses " - f"{token_count} tokens and exceeds DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS " - f"({token_limit})" + f"reasoning.custom_instructions uses {token_count} tokens and exceeds DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS ({token_limit})" ) return value @@ -56,7 +54,7 @@ class ReasoningConfiguration(BaseModel): description="Optional custom instructions for the reasoning system on this workspace/session/message. May be omitted or set to a blank string. Non-blank values are rejected if they exceed the explicitly configured deriver custom-instructions token budget.", ) - _validate_custom_instructions = field_validator( + _validate_custom_instructions: ClassVar[Any] = field_validator( "custom_instructions", mode="after" )(_validate_custom_instructions_budget) @@ -163,7 +161,7 @@ class ResolvedReasoningConfiguration(BaseModel): enabled: bool custom_instructions: str | None = None - _validate_custom_instructions = field_validator( + _validate_custom_instructions: ClassVar[Any] = field_validator( "custom_instructions", mode="after" )(_validate_custom_instructions_budget) diff --git a/tests/routes/test_sessions.py b/tests/routes/test_sessions.py index 4b90f63c..5d396441 100644 --- a/tests/routes/test_sessions.py +++ b/tests/routes/test_sessions.py @@ -1,5 +1,6 @@ from typing import Any +import pytest from fastapi.testclient import TestClient from nanoid import generate as generate_nanoid @@ -93,7 +94,7 @@ def test_create_session_with_configuration( def test_create_session_rejects_over_budget_reasoning_custom_instructions( client: TestClient, sample_data: tuple[Workspace, Peer], - monkeypatch, + monkeypatch: pytest.MonkeyPatch, ): test_workspace, test_peer = sample_data session_id = str(generate_nanoid())