fix: resolve pyright type errors in api.py and test_api.py
lint / lint (push) Successful in 1m57s
test / unit (pull_request) Successful in 45s
test / integration (pull_request) Successful in 21s
test / coverage (pull_request) Failing after 57s

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 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 20:26:37 +00:00
parent 520e6f545d
commit e6cafa39e0
2 changed files with 6 additions and 6 deletions
+5 -5
View File
@@ -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)
+1 -1
View File
@@ -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)