Skip to content

Commit 54288b6

Browse files
committed
Fix pyright configuration and type errors in loop.py
- Add working-directory parameter to pyright-action to scope checks to computer-use-demo - Fix type errors in loop.py by using proper isinstance checks and type casting - Use .get() for safe dictionary access and cast to BetaToolUseBlockParam - Replace .pop() with conditional del for cache_control removal
1 parent 97ba4d7 commit 54288b6

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
pip install -r dev-requirements.txt
3939
- run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
4040
- uses: jakebailey/pyright-action@v1
41+
with:
42+
working-directory: computer-use-demo
4143
pytest:
4244
runs-on: ubuntu-latest
4345
defaults:

computer-use-demo/computer_use_demo/loop.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ async def sampling_loop(
169169
tool_result_content: list[BetaToolResultBlockParam] = []
170170
for content_block in response_params:
171171
output_callback(content_block)
172-
if content_block.get("type") == "tool_use":
172+
if isinstance(content_block, dict) and content_block.get("type") == "tool_use":
173+
# Type narrowing for tool use blocks
173174
tool_use_block = cast(BetaToolUseBlockParam, content_block)
174175
result = await tool_collection.run(
175176
name=tool_use_block["name"],
176-
tool_input=cast(dict[str, Any], tool_use_block["input"]),
177+
tool_input=cast(dict[str, Any], tool_use_block.get("input", {})),
177178
)
178179
tool_result_content.append(
179180
_make_api_tool_result(result, tool_use_block["id"])
@@ -278,7 +279,8 @@ def _inject_prompt_caching(
278279
{"type": "ephemeral"}
279280
)
280281
else:
281-
content[-1].pop("cache_control", None)
282+
if isinstance(content[-1], dict) and "cache_control" in content[-1]:
283+
del content[-1]["cache_control"] # type: ignore
282284
# we'll only every have one extra turn per loop
283285
break
284286

0 commit comments

Comments
 (0)