Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fix: add type ignores for pyright in cache tests

Pyry Takala5a3d340ec407
diff --git a/browser_use/llm/tests/test_anthropic_cache.py b/browser_use/llm/tests/test_anthropic_cache.py
index e9574a147..71644e9b5 100644
--- a/browser_use/llm/tests/test_anthropic_cache.py
+++ b/browser_use/llm/tests/test_anthropic_cache.py
@@ -288,13 +288,14 @@ class TestAnthropicCache:
content_blocks = serialized['content']
# Count blocks with cache_control
- cache_count = sum(1 for block in content_blocks if block.get('cache_control') is not None)
+ # Note: content_blocks are dicts at runtime despite type annotations
+ cache_count = sum(1 for block in content_blocks if block.get('cache_control') is not None) # type: ignore[attr-defined]
assert cache_count == 1, f'Expected 1 cache_control block, got {cache_count}'
# Verify it's the last block
- assert content_blocks[-1].get('cache_control') is not None
- assert content_blocks[0].get('cache_control') is None
- assert content_blocks[1].get('cache_control') is None
+ assert content_blocks[-1].get('cache_control') is not None # type: ignore[attr-defined]
+ assert content_blocks[0].get('cache_control') is None # type: ignore[attr-defined]
+ assert content_blocks[1].get('cache_control') is None # type: ignore[attr-defined]
def test_cache_only_last_tool_call(self):
"""Test that only the LAST tool_use block gets cache_control."""
@@ -310,13 +311,14 @@ class TestAnthropicCache:
content_blocks = serialized['content']
# Count tool_use blocks with cache_control
- cache_count = sum(1 for block in content_blocks if block.get('cache_control') is not None)
+ # Note: content_blocks are dicts at runtime despite type annotations
+ cache_count = sum(1 for block in content_blocks if block.get('cache_control') is not None) # type: ignore[attr-defined]
assert cache_count == 1, f'Expected 1 cache_control block, got {cache_count}'
# Verify it's the last tool_use block
- assert content_blocks[-1].get('cache_control') is not None
- assert content_blocks[0].get('cache_control') is None
- assert content_blocks[1].get('cache_control') is None
+ assert content_blocks[-1].get('cache_control') is not None # type: ignore[attr-defined]
+ assert content_blocks[0].get('cache_control') is None # type: ignore[attr-defined]
+ assert content_blocks[1].get('cache_control') is None # type: ignore[attr-defined]
def test_cache_assistant_with_content_and_tools(self):
"""Test AssistantMessage with both content and tool calls - only last tool gets cache."""
@@ -338,11 +340,12 @@ class TestAnthropicCache:
assert len(content_blocks) == 3
# Only the last block (tool_use) should have cache_control
- cache_count = sum(1 for block in content_blocks if block.get('cache_control') is not None)
+ # Note: content_blocks are dicts at runtime despite type annotations
+ cache_count = sum(1 for block in content_blocks if block.get('cache_control') is not None) # type: ignore[attr-defined]
assert cache_count == 1, f'Expected 1 cache_control block, got {cache_count}'
- assert content_blocks[-1].get('cache_control') is not None # Last tool_use block
- assert content_blocks[0].get('cache_control') is None # First text block
- assert content_blocks[1].get('cache_control') is None # Second text block
+ assert content_blocks[-1].get('cache_control') is not None # type: ignore[attr-defined] # Last tool_use block
+ assert content_blocks[0].get('cache_control') is None # type: ignore[attr-defined] # First text block
+ assert content_blocks[1].get('cache_control') is None # type: ignore[attr-defined] # Second text block
if __name__ == '__main__':