toml
toml copied to clipboard
Comments without a parent throw an Exception
Example TOML:
# Start of TOML file - invalid comment
[[test]]
round = true
>>> a = """
... # Start of TOML file - invalid comment
... [[test]]
... round = true
... """
>>> toml.loads(a, decoder=toml.TomlPreserveCommentDecoder())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\amunchet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\toml\decoder.py", line 374, in loads
decoder.embed_comments(idx, currentlevel)
File "C:\Users\amunchet\AppData\Local\Programs\Python\Python38-32\lib\site-packages\toml\decoder.py", line 1056, in embed_comments
currentlevel[key] = CommentValue(currentlevel[key], comment, beginline,
KeyError: ''
Edit - this is specifically with decoder=toml.TomlPreserveCommentDecoder()
I will open a PR to fix.
Which version of the toml
library are you using? I have CPython 3.9.4 and toml 0.10.2, and your TOML example loads without errors on my system.
>>> s=r'''# Start of TOML file - invalid comment
... [[test]]
... round = true'''
>>> import toml
>>> d=toml.loads(s)
>>> d
{'test': [{'round': True}]}
My case deals specifically with comments - include decoder=toml.TomlPreserveCommentDecoder()
to receive the error. I edited my issue to clarify.
>>> toml.__version__
'0.10.2'
(can confirm as well, with the PreserveComment enco/decoder)
would also very much appreciate if the issue gets resolved soon (considering there seem already to be a PR pending)