-
-
Notifications
You must be signed in to change notification settings - Fork 111
Closed
Description
I am trying to set dotted keys on an already existing super table. This seems to go wrong during the render method, because the code thinks I want to render everything as a super table.
My code:
import tomlkit
doc = tomlkit.loads("""
[output.netcdf_scalar]
value = 5
""")
output_table = doc["output"]
output_table[tomlkit.key(["csv", "path"])] = "output.csv"
print(tomlkit.dumps(doc))Output:
csv.path = "output.csv"
[output.netcdf_scalar]
value = 5Expected:
[output.csv]
path = "output.csv"
[output.netcdf_scalar]
value = 5In the case of rendering the toml, it will say that the item "csv" is dotted, while "output" is not dotted, and "csv" is a super table, so it will not render "output" as prefix. But just adding the prefix will be wrong, because you actually need to at the [output.csv] table as a head, instead of writing output.csv.path.
Lines 551 to 566 in 8c963db
| for k, v in table.value.body: | |
| if isinstance(v, Table): | |
| if ( | |
| cur.strip(" ") | |
| and not cur.strip(" ").endswith("\n") | |
| and "\n" not in v.trivia.indent | |
| ): | |
| cur += "\n" | |
| if v.is_super_table(): | |
| if k.is_dotted() and not key.is_dotted(): | |
| # Dotted key inside table | |
| cur += self._render_table(k, v) | |
| else: | |
| cur += self._render_table(k, v, prefix=_key) | |
| else: | |
| cur += self._render_table(k, v, prefix=_key) |
I think that the _handle_dotted_key function is in this case not able to indicate that "csv" should not be super:
Lines 123 to 126 in 8c963db
| table = current = Table(Container(True), Trivia(), False, is_super_table=True) | |
| for _name in mid: | |
| _name._dotted = True | |
| new_table = Table(Container(True), Trivia(), False, is_super_table=True) |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels