Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Fix repeated whitespace when removing an array item. ([#405](https://github.com/python-poetry/tomlkit/issues/405))
- Fix invalid serialization after removing array item if the comma is on its own line. ([#408](https://github.com/python-poetry/tomlkit/issues/408))
- Fix serialization of a nested dotted key table. ([#411](https://github.com/python-poetry/tomlkit/issues/411))
- Refine the error message when use non-string as single key. ([#412](https://github.com/python-poetry/tomlkit/issues/412))
- Fix invalid serialization after overwriting a key of a out-of-order table. ([#414](https://github.com/python-poetry/tomlkit/issues/414))

Expand Down
6 changes: 6 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ def test_dump_to_file_object():
assert fp.getvalue() == 'foo = "bar"\n'


def test_dump_nested_dotted_table():
a = tomlkit.parse("a.b.c.d='e'")["a"]
assert a == {"b": {"c": {"d": "e"}}}
assert dumps(a) == "b.c.d='e'"


def test_integer():
i = tomlkit.integer("34")

Expand Down
6 changes: 4 additions & 2 deletions tomlkit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ def dumps(data: Mapping, sort_keys: bool = False) -> str:
"""
Dumps a TOMLDocument into a string.
"""
if not isinstance(data, Container) and isinstance(data, Mapping):
if not isinstance(data, (Table, InlineTable, Container)) and isinstance(
data, Mapping
):
data = item(dict(data), _sort_keys=sort_keys)

try:
# data should be a `Container` (and therefore implement `as_string`)
# for all type safe invocations of this function
return data.as_string() # type: ignore[attr-defined]
except AttributeError as ex:
msg = f"Expecting Mapping or TOML Container, {type(data)} given"
msg = f"Expecting Mapping or TOML Table or Container, {type(data)} given"
raise TypeError(msg) from ex


Expand Down
Loading