mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
refactor(parser): deprecate find_tool_units and get_message_content_text
Nothing in the product calls either function; their only callers are tests in tests/test_parser.py. find_tool_units looks like a leftover of the retired rolling-window stage. headroom.parser is imported by the org's consumer repos, so both are deprecated rather than deleted. Each now emits a DeprecationWarning (stacklevel=2); neither has a replacement. The existing tests stay, with a filterwarnings mark, and two small tests check that the warning fires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a9815bbb5f
commit
d31b7f7b79
+20
-1
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import warnings
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from .config import Block, WasteSignals
|
||||
@@ -539,7 +540,16 @@ def find_tool_units(messages: list[dict[str, Any]]) -> list[tuple[int, list[int]
|
||||
|
||||
Returns:
|
||||
List of (assistant_index, [tool_response_indices]) tuples.
|
||||
|
||||
.. deprecated::
|
||||
Nothing in Headroom uses it since the rolling-window stage was
|
||||
retired. It has no replacement.
|
||||
"""
|
||||
warnings.warn(
|
||||
"find_tool_units is deprecated and will be removed in a future release; it has no replacement.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
units: list[tuple[int, list[int]]] = []
|
||||
|
||||
# Build map of tool_call_id -> message index for tool responses
|
||||
@@ -608,7 +618,16 @@ def find_tool_units(messages: list[dict[str, Any]]) -> list[tuple[int, list[int]
|
||||
|
||||
|
||||
def get_message_content_text(message: dict[str, Any]) -> str:
|
||||
"""Extract text content from a message."""
|
||||
"""Extract text content from a message.
|
||||
|
||||
.. deprecated::
|
||||
Nothing in Headroom uses it. It has no replacement.
|
||||
"""
|
||||
warnings.warn(
|
||||
"get_message_content_text is deprecated and will be removed in a future release; it has no replacement.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
content = message.get("content")
|
||||
if content is None:
|
||||
return ""
|
||||
|
||||
@@ -489,6 +489,7 @@ class TestStreamingToolCallObjects:
|
||||
assert tool_call_blocks[0].flags.get("function_name") == "dummy_tool"
|
||||
assert "dummy_tool" in tool_call_blocks[0].text
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:find_tool_units is deprecated:DeprecationWarning")
|
||||
def test_find_tool_units_with_sdk_tool_call(self):
|
||||
"""The second `.get()` site: find_tool_units must still pair an
|
||||
SDK-object tool_call with its tool response message."""
|
||||
@@ -675,6 +676,7 @@ class TestRereadDetection:
|
||||
# --- TestFindToolUnits ---
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:find_tool_units is deprecated:DeprecationWarning")
|
||||
class TestFindToolUnits:
|
||||
"""Tests for find_tool_units function."""
|
||||
|
||||
@@ -864,6 +866,7 @@ class TestFindToolUnits:
|
||||
# --- TestGetMessageContentText ---
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:get_message_content_text is deprecated:DeprecationWarning")
|
||||
class TestGetMessageContentText:
|
||||
"""Tests for get_message_content_text function."""
|
||||
|
||||
@@ -931,6 +934,16 @@ class TestGetMessageContentText:
|
||||
assert text == ""
|
||||
|
||||
|
||||
def test_find_tool_units_is_deprecated() -> None:
|
||||
with pytest.warns(DeprecationWarning, match="find_tool_units is deprecated"):
|
||||
assert find_tool_units([]) == []
|
||||
|
||||
|
||||
def test_get_message_content_text_is_deprecated() -> None:
|
||||
with pytest.warns(DeprecationWarning, match="get_message_content_text is deprecated"):
|
||||
assert get_message_content_text({"content": "hi"}) == "hi"
|
||||
|
||||
|
||||
# --- Additional fixtures for complex tests ---
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user