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

KeyAlreadyPresent exception for a seemingly valid document. #148

Closed
canburak opened this issue Oct 24, 2021 · 0 comments · Fixed by #151
Closed

KeyAlreadyPresent exception for a seemingly valid document. #148

canburak opened this issue Oct 24, 2021 · 0 comments · Fixed by #151

Comments

@canburak
Copy link

Following document looks like legit, but when I try to parse it I get tomlkit.exceptions.KeyAlreadyPresent: Key "scripts" already exists. exception with tomlkit 0.7.2.

document

[tool.poetry]

[tool.isort]

[tool.poetry.dev-dependencies]

[build-system]

[tool.poetry.scripts]

stacktrace

Traceback (most recent call last):
  File "/Users/ccilingi/prepos/tomlbug/tomltest.py", line 21, in <module>
    regular_dict = dict(parsed)
  File "/Users/ccilingi/Library/Caches/pypoetry/virtualenvs/tomlbug-EdMsyBII-py3.9/lib/python3.9/site-packages/tomlkit/container.py", line 559, in __getitem__
    return OutOfOrderTableProxy(self, idx)
  File "/Users/ccilingi/Library/Caches/pypoetry/virtualenvs/tomlbug-EdMsyBII-py3.9/lib/python3.9/site-packages/tomlkit/container.py", line 699, in __init__
    self._internal_container.append(k, v)
  File "/Users/ccilingi/Library/Caches/pypoetry/virtualenvs/tomlbug-EdMsyBII-py3.9/lib/python3.9/site-packages/tomlkit/container.py", line 169, in append
    current.append(k, v)
  File "/Users/ccilingi/Library/Caches/pypoetry/virtualenvs/tomlbug-EdMsyBII-py3.9/lib/python3.9/site-packages/tomlkit/items.py", line 922, in append
    self._value.append(key, _item)
  File "/Users/ccilingi/Library/Caches/pypoetry/virtualenvs/tomlbug-EdMsyBII-py3.9/lib/python3.9/site-packages/tomlkit/container.py", line 175, in append
    raise KeyAlreadyPresent(key)
tomlkit.exceptions.KeyAlreadyPresent: Key "scripts" already exists.

code

You can run the following python script to reproduce:

from tomlkit import parse
import ast
from pprint import pprint

doc = """
[tool.poetry]

[tool.isort]

[tool.poetry.dev-dependencies]

[build-system]

[tool.poetry.scripts]
"""

parsed = parse(doc)
as_str = str(parsed)
eval_dict = ast.literal_eval(as_str)
pprint(eval_dict)
regular_dict = dict(parsed)

This is the contents of eval_dict:

{'build-system': {},
 'tool': {'isort': {}, 'poetry': {'dev-dependencies': {}, 'scripts': {}}}}
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

Successfully merging a pull request may close this issue.

1 participant