kyegomez/swarms
[Cleanup] Four overlapping 'format any data structure as a string' helpers (~80 lines) — keep one
開放
#1,851 建立於 2026年8月9日
good first issuetech-debtutils
倉庫指標
- 星標
- (7,040 顆星)
- PR 合併指標
- (平均合併 3天 5小時) (30 天內合併 17 個 PR)
描述
What
Four separate helpers recursively walk dict/list/tuple structures and produce an indented key: value string. They differ only in bracket and quote cosmetics.
| Function | Location | Lines | Callers |
|---|---|---|---|
format_data_structure |
swarms/utils/index.py:46-155 |
110 | agent.py ×7 |
format_dict_to_string |
swarms/utils/index.py:13-43 |
31 | 0 (only the __init__ re-export) |
any_to_str |
swarms/utils/any_to_str.py:4-63 |
60 | consistency_agent, swarm_rearrange, conversation, agent_rearrange, model_router |
function_to_str / functions_to_str |
swarms/tools/func_to_str.py |
42 | reachable only via the dead base_tool methods |
Analysis
format_dict_to_stringis strictly redundant —format_data_structurealready handles every case it does, and it has zero callers. Pure deletion.any_to_strandformat_data_structuregenuinely overlap — same traversal, different output cosmetics. They can be one function with astyle=parameter.func_to_str.pydies automatically with thebase_tool.pydead-method cleanup (see that issue) — nothing else reaches it.
Why it matters
Two of these are used by different parts of the same codebase to render the same kinds of objects, so the same dict can be printed two different ways depending on which call path reached it. Consolidating gives one predictable output format.
Scope
- Delete
format_dict_to_string(31 lines, 0 callers) and its__init__re-export - Fold
any_to_strintoformat_data_structurewith astyle=flag; update the 5 call sites, keepingany_to_stras a thin alias if churn is a concern - Confirm
func_to_str.pyis removed alongside thebase_toolcleanup - Add a table test pinning the exact output for a nested dict/list/tuple fixture in each style, so the consolidation is provably behavior-preserving
Context
From the code-waste audit (experimental/CODE_WASTE_AUDIT.md, section 3.5).
🤖 Generated with Claude Code