kyegomez/swarms

[Cleanup] Four overlapping 'format any data structure as a string' helpers (~80 lines) — keep one

Aberta

#1.851 aberto em 9 de ago. de 2026

 (0 comentário) (0 reação) (0 responsável)Python (986 forks)github user discovery
good first issuetech-debtutils

Métricas do repositório

Stars
 (7.040 estrelas)
Métricas de merge de PR
 (Mesclagem média 3d 5h) (17 fundiu PRs em 30d)

Description

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_string is strictly redundantformat_data_structure already handles every case it does, and it has zero callers. Pure deletion.
  • any_to_str and format_data_structure genuinely overlap — same traversal, different output cosmetics. They can be one function with a style= parameter.
  • func_to_str.py dies automatically with the base_tool.py dead-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_str into format_data_structure with a style= flag; update the 5 call sites, keeping any_to_str as a thin alias if churn is a concern
  • Confirm func_to_str.py is removed alongside the base_tool cleanup
  • 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

Guia do colaborador