Skip to content

cleanup: consolidate format helpers, add style parameter - #1858

Open
RawNuke wants to merge 1 commit into
kyegomez:masterfrom
RawNuke:cleanup/consolidate-format-helpers
Open

cleanup: consolidate format helpers, add style parameter#1858
RawNuke wants to merge 1 commit into
kyegomez:masterfrom
RawNuke:cleanup/consolidate-format-helpers

Conversation

@RawNuke

@RawNuke RawNuke commented Aug 9, 2026

Copy link
Copy Markdown

What

Consolidates the four overlapping format helpers as described in #1851.

Changes

  • Delete format_dict_to_string (31 lines, 0 callers) and its re-export from swarms/utils/__init__.py
  • Add style parameter to format_data_structure: "indented" (default, existing behavior) and "compact" (matches any_to_str output)
  • Make any_to_str a thin alias that calls format_data_structure(data, style="compact") — all 5+ call sites continue to work with no changes
  • func_to_str.py is left for the base_tool cleanup since no live code reaches it
  • Add 16 parametrized table tests pinning exact output for nested dict/list/tuple fixtures in both styles
  • All 10 existing any_to_str tests pass unchanged

Why

Two functions (any_to_str and format_data_structure) were used by different parts of the codebase to render the same kinds of objects, producing inconsistent output. Now there is one function with a predictable output format per style.

How to test

python -m pytest tests/utils/test_any_to_str.py tests/utils/test_format_data_structure.py -v

26 tests pass.

If this helped, RawNuke welcomes sponsorship: https://github.com/sponsors/RawNuke

Delete format_dict_to_string (0 callers, redundant with format_data_structure).
Add style='compact' mode to format_data_structure that matches any_to_str output.
Make any_to_str a thin alias for format_data_structure(style='compact').
Add table tests for both indented and compact styles.

Closes kyegomez#1851

Signed-off-by: RawNuke <67506722+RawNuke@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant