Repository navigation
Keep valid TOML when deleting the last dotted key in an inline table - #687
mayur-dhavan wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Note on the failing check: |
|
Explain why not #664 |
|
Honest answer: there isn't a good reason - I missed #664 when checking for existing work on #662. Comparing the two now: same root cause, same approach (render the emptied dotted-key table as an empty inline table), equivalent coverage of all separator positions and the nested |
Fixes #662.
Problem
Deleting the last child of a dotted key inside an inline table emitted nothing for the key, leaving a dangling separator:
Depending on the key's position this produced a leading comma (
{, a = 1}), a trailing comma ({a = 1, }), or silently droppedbwhen it was the only key.Fix
In
InlineTable._render_dotted(tomlkit/items.py), a dotted key whose children were all removed now renders as an empty inline table instead of nothing, both at the top level and for nested dotted children:t = {a="", b.c=1, d=1}->t = {a="", b={}, d=1}t = {a="", b.c.d=1, e=1}(deleted) ->t = {a="", b.c={}, e=1}The document model still holds the emptied table after the deletion, so rendering it as
{}keeps the output faithful and parseable.Tests
Three regression tests in
tests/test_toml_document.py(middle/first/last/only-key positions, nested dotted child), each asserting the exact output and, where available, atomllibround-trip. Full suite passes locally: 1206 passed (includes the toml-test cases).AI disclosure: this contribution was prepared with AI assistance (an automated coding agent acting on behalf of the author); the change and tests were validated locally against the project's test suite as described above.