Skip to content

Replace toml with tomli w - #973

Merged
mauvilsa merged 2 commits into
mainfrom
replace-toml-with-tomli-w
Sep 11, 2026
Merged

Replace toml with tomli w#973
mauvilsa merged 2 commits into
mainfrom
replace-toml-with-tomli-w

Conversation

@mauvilsa

@mauvilsa mauvilsa commented Sep 11, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Fixes #962

Moves the toml extra off the unmaintained toml package.

Reading already preferred the standard library tomllib when available, so the only real dependency on toml was writing, plus reading in python 3.10 where tomllib does not exist. The extra now installs:

  • tomli-w for writing.
  • tomli for reading, only for python_version < '3.11'.

Changes:

  • pyproject.toml: the toml extra requires tomli-w>=1.0.0 and tomli>=2.0.1; python_version < '3.11'. The extra name is unchanged.
  • _optionals.py: toml_load_available now checks tomllib or tomli, toml_dump_available checks tomli_w, and import_toml_loads / import_toml_dumps import accordingly.
  • .pre-commit-config.yaml: dropped the types-toml mypy dependency, since tomli and tomli-w ship their own type hints.

Note on behavior: tomli-w writes arrays multi-line, where toml wrote them inline. So dumping a list now gives:

child2 = [
    3.0,
    4.5,
]

instead of child2 = [ 3.0, 4.5,]. The output is still valid TOML and parses back to the same value, but it is a visible difference for anyone comparing dumped configs, so it is mentioned in the changelog.

Before submitting

  • Did you read the contributing guideline?
  • If you used a coding agent, did you fully understand and validate all generated code and ensure it follows the contributing guidelines?
  • [n/a] Did you update the documentation? (readme and public docstrings)
  • [n/a] Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • [n/a] If this is a bug fix, did you verify that the tests fail without the code fix?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG including a pull request link? (not for typos, docs, test updates, or minor internal changes/refactors)

@mauvilsa mauvilsa added the refactor Improvements to the quality of the code label Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (41fccd0) to head (038ce73).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #973   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         8734      8734           
=========================================
  Hits          8734      8734           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit 95aab43 into main Sep 11, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the replace-toml-with-tomli-w branch September 11, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Improvements to the quality of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jsonargparse, please move away from toml to tomli_w

1 participant