Skip to content

Multiline inline-tables are allowed in TOML 1.1.0, but not yet supported by tomlkit #465

@nmay231

Description

@nmay231

Using tomlkit 0.14.0 and trying to read the following example:

# example.toml
[my_table]
key = {
   inner = 1
}

Running:

uv run python -c "import tomlkit, pathlib; tomlkit.loads(pathlib.Path('./example.toml').read_text())"

Gets the following error:

tomlkit.exceptions.EmptyKeyError: Empty key at line 3 col 7

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import tomlkit, pathlib; tomlkit.loads(pathlib.Path('./example.toml').read_text())
                             ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/api.py", line 52, in loads
    return parse(string)
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/api.py", line 99, in parse
    return Parser(string).parse()
           ~~~~~~~~~~~~~~~~~~~~^^
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 154, in parse
    key, value = self._parse_table()
                 ~~~~~~~~~~~~~~~~~^^
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 1001, in _parse_table
    item = self._parse_item()
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 238, in _parse_item
    return self._parse_key_value(True)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 331, in _parse_key_value
    val = self._parse_value()
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 437, in _parse_value
    return self._parse_inline_table()
           ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 654, in _parse_inline_table
    key, val = self._parse_key_value(False)
               ~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 311, in _parse_key_value
    key = self._parse_key()
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 360, in _parse_key
    return self._parse_bare_key()
           ~~~~~~~~~~~~~~~~~~~~^^
  File "/home/acsi/tmp-tomlkit-bug/.venv/lib/python3.13/site-packages/tomlkit/parser.py", line 404, in _parse_bare_key
    raise self.parse_error(EmptyKeyError)
tomlkit.exceptions.EmptyKeyError: Empty key at line 3 col 7

And according to the TOML 1.1.0 spec, newlines inside of inline tables should now be supported.

Inline tables can have multiple key/value pairs on the same line, or they can be put on different lines. A terminating comma (also called trailing comma) is permitted after the last key/value pair.

Thank you for your time and effort with this package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions