Repository navigation
Conversation
Deleting the last key under a dotted prefix in an inline table left an
empty slot between two commas:
>>> doc = parse('t = {a = "", b.c = 1, d = 1}\n')
>>> del doc["t"]["b"]["c"]
>>> doc.as_string()
't = {a = "", , d = 1}\n'
_render_dotted renders one "prefix.child = value" pair per child, so an
emptied table produced no pairs at all while the separators around it
were still emitted. Render it as "b = {}" instead, which keeps the empty
table the document still holds and gives valid TOML wherever the key
sits in the inline table.
|
Here's a small optional test-only commit, based directly on your current head. It checks both Two guards worth keeping: the dot stays part of the quoted key, and the empty table remains usable when refilled. On Python 3.14.4, both new cases pass your source and hit the expected empty-state decoding error on the base. The existing dotted/nested append tests pass on both. Ruff 0.15.11 lint/format passes; I haven't run the configured 0.17.0 hooks, mypy, full corpus/suite, build or CI matrix. The oracle test explicitly skips below Python 3.11. To run the added file in your tree: |
Wkhanex
left a comment
There was a problem hiding this comment.
AI-assisted validation at 6ada78613109 on Python 3.12.14: I tried emptying two dotted subtrees in the same inline table, both at one level (a={b.c=1, d.e=2}) and nested (a={x=0,b.c.d=1,d.e.f=2,y=3}). After deleting the leaves, both tomllib and TOMLKit recovered the expected empty dictionaries; adding a new sibling under b also round-tripped correctly. The seven focused dotted-inline-table tests passed.
This adds a slightly different boundary from the quoted-key/refill example already in the discussion: adjacent emptied subtrees must each keep their own rendered slot without introducing an empty comma-separated entry. That case appears worth keeping as a regression.
|
Thanks, I ran it: both cases pass on this branch and fail on master. If the maintainers want the quoted-key case covered I'd rather add it as another row in the existing parametrized test than a new file. |
Fixes #662. Inside an inline table a dotted-key table is rendered as one
prefix.child = valuepair per child, so once every child is deleted it renders nothing and the separators around it leave, ,(or a stray leading/trailing comma). The fix renders the emptied table asb = {}, which matches the data and follows how #567 handles an emptied array of tables.