Closed andreasdoll closed 4 months ago
Comments are not tied to the array items because there is no clear relation between them, you may think there is, look at this example:
a = [
"item1", "item2", # type a items
"item3", "item4", # type b items
]
What do the comment belong to? A natural idea is that the annotation follows the previous item, right? But what should happen when user removes "item2" from the list? If the comment is with the item, it will be gone too. But in this case, the comment is about the line, not any specific item. I think you would agree the comment should remain in this case. There are other examples, too, such as comments can appear in its own line.
There are some private methods to do this:
item = array._value[array._index_map[i]]
comment = item.comment
Thank you for your counter-example, I agree with your reasoning but didn't consider such a case since I'm used to write one element per line.
Hello
I have two questions regarding comments in multiline arrays (for which I couldn't find documentation).
I'm using tomlkit 0.12.4. Consider the following code:
I was expecting
data["foo"]["bar"][0].trivia
, but this doesn't have information about the comment (neither doesdata["foo"]["bar"].trivia
). I know I can dodata["foo"]["bar"].as_string()
but there I'd have to parse them myself from the string.Thanks in advance!