Skip to content

"IndexError: list index out of range" when using dotkeys and non-dotkeys #273

Closed

Description

@fflorent

Version of tomlkit: 0.11.6

I get an exception when running this script (this seems to be the minimal scenario):

import tomlkit

t = tomlkit.table()
t.add('foo', 2)
t.add(tomlkit.key(["bar", "baz"]), 1)
t.add(tomlkit.key(["bar", "qux"]), 1)

I expect to be able to output something like this (using t.as_string()):

foo = 2
bar.baz = 1
bar.qux = 1

Instead, I get this exception:

Traceback (most recent call last):
  File "/tmp/script.py", line 6, in <module>
    t.add(tomlkit.key(["bar", "qux"]), 1)
  File "/usr/lib/python3/dist-packages/tomlkit/items.py", line 1478, in add
    return self.append(key, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/tomlkit/items.py", line 1584, in append
    self._value.append(key, _item)
  File "/usr/lib/python3/dist-packages/tomlkit/container.py", line 188, in append
    self._handle_dotted_key(key, item)
  File "/usr/lib/python3/dist-packages/tomlkit/container.py", line 150, in _handle_dotted_key
    self.append(name, value)
  File "/usr/lib/python3/dist-packages/tomlkit/container.py", line 243, in append
    self._table_keys[-1] != current_body_element[0]
    ~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range

Activity

  1. frostming commented on Apr 27, 2023

    @frostming
    Contributor

    This should be fixed by #284

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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