Skip to content

feat: migrate from tomlkit to tomlrt#10877

Open
dimbleby wants to merge 1 commit intopython-poetry:mainfrom
dimbleby:tomlrt
Open

feat: migrate from tomlkit to tomlrt#10877
dimbleby wants to merge 1 commit intopython-poetry:mainfrom
dimbleby:tomlrt

Conversation

@dimbleby
Copy link
Copy Markdown
Contributor

@dimbleby dimbleby commented May 3, 2026

I have always found tomlkit a bit disagreeable to work with:

  • the type annotations are unusable
  • the API is fiddly
  • it has been buggy, eg around line endings and out-of-order tables
  • the parser is very slow
  • possibly more that I have forgotten...

So I got to wondering how hard it could be in the AI age to (have the bots) come up with something that I liked better.

The result is tomlrt, and this pull request shows what it would look like to move poetry to using it.

The good news is:

  • the type annotations worked out fine, this pull request cleans out lots of type-checker workarounds
  • the API is simpler:
    • tomlrt tries hard to Do The Right Thing rather than exposing explicit nl() and is_super_table and suchlike
    • and I have included a handful of helpers for navigating nested tables that simplify some calling code
  • so far as I know the code is bug-free
  • the parser is a lot faster

Per the diff, tomlrt prefers to format inline tables with spaces around the curly braces. AFAIK tomlkit is the odd one out among toml tooling in not doing this, but there would be a one-time round of noise in lock files.

For all of the faults of tomlkit: at this point poetry has mostly flushed out most of the bugs that users care about - and that is a pretty good argument for not changing anything. So even I am far from 100% convinced that this pull request is a good idea.

But I figured I should show it to you and let you consider it for yourselves.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In tests/helpers.py, the new toml_dumps_dict helper calls tomlrt.Document at runtime but tomlrt is only imported in TYPE_CHECKING, so you should add a real import of tomlrt at the top of the file to avoid NameError.
  • Several tests now instantiate tomlrt.Document directly (e.g. tests/utils/env/test_env_manager.py, tests/console/commands/env/test_list.py, tests/console/commands/env/test_use.py), but still import tomlkit; update these modules to import tomlrt instead so the new Document calls resolve correctly.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In tests/helpers.py, the new toml_dumps_dict helper calls tomlrt.Document at runtime but tomlrt is only imported in TYPE_CHECKING, so you should add a real import of tomlrt at the top of the file to avoid NameError.
- Several tests now instantiate tomlrt.Document directly (e.g. tests/utils/env/test_env_manager.py, tests/console/commands/env/test_list.py, tests/console/commands/env/test_use.py), but still import tomlkit; update these modules to import tomlrt instead so the new Document calls resolve correctly.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dimbleby dimbleby force-pushed the tomlrt branch 2 times, most recently from 08399c6 to edbe5e7 Compare May 3, 2026 12:11
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

poetry version throws error Key "source" already exists. when sources are not in order in toml-file

1 participant