Description
tomlkit.parse() accepts and exactly round-trips this valid document, but accessing doc["y"] or calling doc.unwrap() raises KeyAlreadyPresent: Key "a" already exists:
from tomlkit import parse
content = """\
[[y.a]]
[b.d.x]
[[y.a.c]]
"""
doc = parse(content)
assert doc.as_string() == content
doc.unwrap() # KeyAlreadyPresent: Key "a" already exists
Python's standard-library tomllib reads it as:
{"y": {"a": [{"c": [{}]}]}, "b": {"d": {"x": {}}}}
The later [[y.a.c]] header extends the last element of the existing y.a array of tables. This works when the parts are adjacent, but an unrelated table makes y out of order. OutOfOrderTableProxy then sees a first as an AoT and later as an implicit Table; its existing fragment merge handles AoT + AoT, but not this AoT + super-table extension.
The example was initially flagged by @chuenchen309 in the description of #565. I reproduced it on current master and narrowed it down to the proxy merge path.
Environment
- tomlkit 0.15.1 / current
master
- Python 3.12
Description
tomlkit.parse()accepts and exactly round-trips this valid document, but accessingdoc["y"]or callingdoc.unwrap()raisesKeyAlreadyPresent: Key "a" already exists:Python's standard-library
tomllibreads it as:{"y": {"a": [{"c": [{}]}]}, "b": {"d": {"x": {}}}}The later
[[y.a.c]]header extends the last element of the existingy.aarray of tables. This works when the parts are adjacent, but an unrelated table makesyout of order.OutOfOrderTableProxythen seesafirst as anAoTand later as an implicitTable; its existing fragment merge handlesAoT+AoT, but not thisAoT+ super-table extension.The example was initially flagged by @chuenchen309 in the description of #565. I reproduced it on current
masterand narrowed it down to the proxy merge path.Environment
master