[CLI] Drop legacy printing helpers from _cli_utils.py#4285
Merged
Conversation
Now that every command has migrated to the `out` singleton, the legacy helpers in `_cli_utils.py` have no callers. The one exception was `api_object_to_dict`, which still served dataclass→dict conversion before `out.table` / JSON serialization — and `_output.py` already exposes the same helper as `_dataclass_to_dict`. So: - Switch every caller (discussions, models, datasets, papers, spaces, collections, _file_listing) from `api_object_to_dict` to `_dataclass_to_dict` from `_output.py`. - Delete from `_cli_utils.py`: `api_object_to_dict`, `_serialize_value`, `print_as_table`, `print_list_output`, `_format_cell`, `_format_value`, `_to_header`, `_MAX_CELL_LENGTH`, plus the legacy option types and enum (`OutputFormat`, `_set_output_mode`, `FormatOpt`, `FormatWithAutoOpt`, `QuietOpt`). Remove now-orphaned imports (`json`, `dataclasses`, `datetime`, `tabulate`, `Union`). - Update `tests/test_cli_output.py` to import `OutputFormatWithAuto` from `_output.py` directly instead of via the `_cli_utils.py` re-export. No behavior change.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Wauplin
approved these changes
May 27, 2026
Wauplin
left a comment
Collaborator
There was a problem hiding this comment.
I love cleaning PRs! 🎉 😄
The legacy `OutputFormat` (table | json) was removed in the previous cleanup PR, freeing up the name. `OutputFormatWithAuto` was always the "real" enum — covering auto/human/agent/json/quiet — so drop the disambiguating suffix. Pure rename, no behavior change. Also removes the now-stale TODO comment in `_output.py` that referenced the (now deleted) legacy enum.
Contributor
|
This PR has been shipped as part of the v1.17.0 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
let's review and merge #4286 before merging this one
Part of #3979 — the final cleanup after every command has been migrated to the
outsingleton.Most of the legacy printing helpers in
_cli_utils.pyhad zero remaining callers (verified by grep acrosssrc/andtests/). The one exception wasapi_object_to_dict, still used to convert dataclasses → dicts beforeout.tableor JSON serialization in 11 callsites — but_output.pyalready exposes the same conversion as_dataclass_to_dict. So this PR does a 1:1 swap and deletes the dead code.Changes
api_object_to_dictto_dataclass_to_dict(imported from._output) indiscussions.py,models.py,datasets.py(×2),papers.py(×2),spaces.py(×4),collections.py,_file_listing.py._cli_utils.py:print_as_table,print_list_output,_format_cell,_format_value,_to_header,_MAX_CELL_LENGTH,_serialize_value,api_object_to_dict.OutputFormat(the oldtable | jsonenum),_set_output_mode,FormatOpt,FormatWithAutoOpt,QuietOpt.json,dataclasses,datetime,tabulate,Union.tests/test_cli_output.pyto importOutputFormatWithAutofrom._outputdirectly instead of via the_cli_utilsre-export.Net diff: +23 / -188 across 9 files. No behavior change.
Verification
Smoke test on a list command that goes through the new path:
Note
Low Risk
Mechanical refactor with tests passing; only risk is if any external code imported removed symbols from
_cli_utils.Overview
This PR finishes CLI output consolidation after migration to the
outsingleton: it removes dead legacy printing code from_cli_utils.pyand routes all dataclass→dict conversion through_output._dataclass_to_dict._cli_utils.py: Deletes unused helpers (print_as_table,print_list_output,api_object_to_dict, legacyOutputFormat/FormatOpt/QuietOpt, etc.) and drops imports that only served that code (tabulate, extrajson/dataclasses/datetimeusage there).Call sites:
discussions,models,datasets,papers,spaces,collections, and_file_listingnow import_dataclass_to_dictfrom._outputinstead ofapi_object_to_dictfrom._cli_utils—same role forout.table()and JSON paths.Tests:
OutputFormatWithAutois imported from._outputintest_cli_output.pyinstead of via_cli_utils.No intended behavior change; large net deletion (~165 lines).
Reviewed by Cursor Bugbot for commit 51107e7. Configure here.