Skip to content

Commit 24b601e

Browse files
Jepson2kclaude
andcommitted
parol6: fix _ToolsCollection membership + by_type for StrEnum ToolType
waldoctl's ToolType is now a StrEnum (category members are also str) and the ToolsSpec.by_type ABC widened to `str | ToolType`: - __contains__: test ToolType before the plain-str branch — otherwise `ToolType.GRIPPER in tools` misrouted to the by-key lookup (keyed by tool key, not category) and returned False. Safe under plain Enum and StrEnum. - by_type: widen the parameter to `str | ToolType` to match the widened ABC (LSP-safe against both the old and new base signatures). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9da1bd2 commit 24b601e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎parol6/robot.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,16 @@ def __getitem__(self, key: str) -> ToolSpec:
404404
return self._by_key[key]
405405

406406
def __contains__(self, item: object) -> bool:
407-
if isinstance(item, str):
408-
return item in self._by_key
407+
# ToolType is a StrEnum, so test it before the plain-str branch —
408+
# otherwise a category like ToolType.GRIPPER would misroute to the
409+
# by-key lookup (keyed by tool key, not category) and return False.
409410
if isinstance(item, ToolType):
410411
return any(t.tool_type == item for t in self._tools)
412+
if isinstance(item, str):
413+
return item in self._by_key
411414
return False
412415

413-
def by_type(self, tool_type: ToolType) -> tuple[ToolSpec, ...]:
416+
def by_type(self, tool_type: str | ToolType) -> tuple[ToolSpec, ...]:
414417
return tuple(t for t in self._tools if t.tool_type == tool_type)
415418

416419

0 commit comments

Comments
 (0)