fix: resolve pyright type errors in api.py and test_api.py
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:
+5
-5
@@ -20,7 +20,7 @@ call sites in ``lifecycle.py`` are unchanged.
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Sequence
|
from typing import Sequence, cast
|
||||||
|
|
||||||
from .backend import BottleSpec
|
from .backend import BottleSpec
|
||||||
from .backend.freeze import CommitCancelled, get_freezer
|
from .backend.freeze import CommitCancelled, get_freezer
|
||||||
@@ -102,7 +102,7 @@ def start_headless(
|
|||||||
headless_prompt_text=prompt,
|
headless_prompt_text=prompt,
|
||||||
)
|
)
|
||||||
except Die as 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
|
||||||
if exit_code != 0:
|
if exit_code != 0:
|
||||||
raise BottleError(
|
raise BottleError(
|
||||||
f"agent exited {exit_code} (slug={slug!r})", exit_code=exit_code
|
f"agent exited {exit_code} (slug={slug!r})", exit_code=exit_code
|
||||||
@@ -155,7 +155,7 @@ def resume_headless(
|
|||||||
headless_prompt_text=prompt,
|
headless_prompt_text=prompt,
|
||||||
)
|
)
|
||||||
except Die as 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
|
||||||
if exit_code != 0:
|
if exit_code != 0:
|
||||||
raise BottleError(
|
raise BottleError(
|
||||||
f"agent exited {exit_code} resuming {slug!r}", exit_code=exit_code
|
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:
|
except CommitCancelled as exc:
|
||||||
raise BottleError(f"freeze cancelled for {slug!r}") from exc
|
raise BottleError(f"freeze cancelled for {slug!r}") from exc
|
||||||
except Die as 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:
|
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
|
# context manager; no persistent VM survives, so nothing extra is
|
||||||
# needed at destroy time beyond the state-dir removal below.
|
# needed at destroy time beyond the state-dir removal below.
|
||||||
except Die as 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
|
||||||
clear_preserve_marker(slug)
|
clear_preserve_marker(slug)
|
||||||
cleanup_state(slug)
|
cleanup_state(slug)
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class TestStartHeadless(unittest.TestCase):
|
|||||||
"bot_bottle.api._launch_bottle", return_value=("implementer-abc12", 0)
|
"bot_bottle.api._launch_bottle", return_value=("implementer-abc12", 0)
|
||||||
).start()
|
).start()
|
||||||
patch(
|
patch(
|
||||||
"bot_bottle.api._uniquify_label_headless", side_effect=lambda lbl: lbl
|
"bot_bottle.api._uniquify_label_headless", side_effect=str
|
||||||
).start()
|
).start()
|
||||||
self.addCleanup(patch.stopall)
|
self.addCleanup(patch.stopall)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user