From e6cafa39e0fb1abb94a3f7d1ea46395ec88d99e3 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 1 Jul 2026 20:26:37 +0000 Subject: [PATCH] fix: resolve pyright type errors in api.py and test_api.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cast Die.code (_ExitCode) to int before passing to BottleError — Die always holds an int but SystemExit.code is typed as str|int|None in typeshed. Replace untyped lambda with str() as identity for _uniquify_label_headless mock (fixes reportUnknownLambdaType). Co-Authored-By: Claude Sonnet 4.6 --- bot_bottle/api.py | 10 +++++----- tests/unit/test_api.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bot_bottle/api.py b/bot_bottle/api.py index a7c4130..bda2840 100644 --- a/bot_bottle/api.py +++ b/bot_bottle/api.py @@ -20,7 +20,7 @@ call sites in ``lifecycle.py`` are unchanged. from __future__ import annotations -from typing import Sequence +from typing import Sequence, cast from .backend import BottleSpec from .backend.freeze import CommitCancelled, get_freezer @@ -102,7 +102,7 @@ def start_headless( headless_prompt_text=prompt, ) except Die as exc: - raise BottleError(exc.message, exit_code=exc.code) from exc + raise BottleError(exc.message, exit_code=cast(int, exc.code)) from exc if exit_code != 0: raise BottleError( f"agent exited {exit_code} (slug={slug!r})", exit_code=exit_code @@ -155,7 +155,7 @@ def resume_headless( headless_prompt_text=prompt, ) except Die as exc: - raise BottleError(exc.message, exit_code=exc.code) from exc + raise BottleError(exc.message, exit_code=cast(int, exc.code)) from exc if exit_code != 0: raise BottleError( f"agent exited {exit_code} resuming {slug!r}", exit_code=exit_code @@ -174,7 +174,7 @@ def freeze(slug: str, *, backend_name: str | None = None) -> None: except CommitCancelled as exc: raise BottleError(f"freeze cancelled for {slug!r}") from exc except Die as exc: - raise BottleError(exc.message, exit_code=exc.code) from exc + raise BottleError(exc.message, exit_code=cast(int, exc.code)) from exc def destroy(slug: str, *, backend_name: str | None = None) -> None: @@ -194,7 +194,7 @@ def destroy(slug: str, *, backend_name: str | None = None) -> None: # context manager; no persistent VM survives, so nothing extra is # needed at destroy time beyond the state-dir removal below. except Die as exc: - raise BottleError(exc.message, exit_code=exc.code) from exc + raise BottleError(exc.message, exit_code=cast(int, exc.code)) from exc clear_preserve_marker(slug) cleanup_state(slug) diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index 6160919..454008f 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -56,7 +56,7 @@ class TestStartHeadless(unittest.TestCase): "bot_bottle.api._launch_bottle", return_value=("implementer-abc12", 0) ).start() patch( - "bot_bottle.api._uniquify_label_headless", side_effect=lambda lbl: lbl + "bot_bottle.api._uniquify_label_headless", side_effect=str ).start() self.addCleanup(patch.stopall)