python-poetry / tomlkit

Style-preserving TOML library for Python
MIT License
699 stars 100 forks source link

Error when removing the first element from array: AttributeError: 'NoneType' object has no attribute 's' #327

Closed pinal005 closed 10 months ago

pinal005 commented 10 months ago

seeing this edge case while removing the first element from the array:

Below code works fine if there is a space before the second element(i.e. "green" in below example) and try to remove the first element.

import tomlkit
doc = tomlkit.loads("""
[colors]
primary = ["red", "green","blue"]
""")

doc["colors"]["primary"].remove("red")

But errors out if there is no space before the second element "green"

import tomlkit
doc = tomlkit.loads("""
[colors]
primary = ["red","green","blue"]
""")
doc["colors"]["primary"].remove("red")

Error:

tomlkit/items.py", line 1415, in __delitem__
    and "\n" not in self._value[idx].indent.s
AttributeError: 'NoneType' object has no attribute 's'