Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fflorent opened this issue Mar 4, 2023 · 1 comment
Closed

Comments

@fflorent
Copy link

fflorent commented Mar 4, 2023

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
@frostming
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants