Skip to content

Honor sort_keys for parsed TOML documents#471

Merged
frostming merged 1 commit intopython-poetry:masterfrom
ShipItAndPray:fix-466-sort-parsed-documents
Apr 27, 2026
Merged

Honor sort_keys for parsed TOML documents#471
frostming merged 1 commit intopython-poetry:masterfrom
ShipItAndPray:fix-466-sort-parsed-documents

Conversation

@ShipItAndPray
Copy link
Copy Markdown
Contributor

Summary

  • honor sort_keys=True when dumping parsed TOMLDocument / container values
  • keep the existing fast path for unsorted container dumps
  • add regression coverage for loads() + dumps(sort_keys=True)

Closes #466.

Validation

Autoresearch-style binary gates:

  • E1 baseline repro exists: tomlkit.dumps(tomlkit.loads('zzz = 1\naaa = "foo"'), sort_keys=True) preserved the original order on master
  • E2 regression expectation fails on baseline: the new test expects sorted output for a parsed document
  • E3 regression passes after fix: parsed documents now dump as 'aaa = "foo"\nzzz = 1\n'
  • E4 targeted tests pass:
    • python3 -m pytest tests/test_api.py -k 'sorted_keys or raw_dict_can_be_dumped or mapping_types_can_be_dumped'
  • E5 broader nearby suite passes:
    • python3 -m pytest tests/test_api.py

Notes

The fix only changes the sort_keys=True container path. Unsorted container dumps still use the existing direct as_string() fast path.

@frostming frostming merged commit 2c87eaf into python-poetry:master Apr 27, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sort_keys does not (always?) work

3 participants