python-poetry / tomlkit

Style-preserving TOML library for Python
MIT License
693 stars 98 forks source link

AttributeError: 'Null' object has no attribute '_trivia'. Did you mean: 'trivia'? #313

Closed dimbleby closed 1 year ago

dimbleby commented 1 year ago
[dependencies]
[dependencies.foo]
version = ">=1.0.0"

[dependencies.bar]
version = ">=1.0.0"
#!/usr/bin/env python3

from tomlkit.toml_file import TOMLFile

content = TOMLFile("dependencies.toml").read()
content["dependencies"]["foo"] = ">=2.0.0"
Traceback (most recent call last):
  File "/home/dch/bar/./foo.py", line 6, in <module>
    content["dependencies"]["foo"] = ">=2.0.0"
  File "/home/dch/.virtualenvs/foo/lib/python3.10/site-packages/tomlkit/items.py", line 1518, in __setitem__
    self._value[key] = value
  File "/home/dch/.virtualenvs/foo/lib/python3.10/site-packages/tomlkit/container.py", line 630, in __setitem__
    self._replace(old_key, key, value)
  File "/home/dch/.virtualenvs/foo/lib/python3.10/site-packages/tomlkit/container.py", line 649, in _replace
    self._replace_at(idx, new_key, value)
  File "/home/dch/.virtualenvs/foo/lib/python3.10/site-packages/tomlkit/container.py", line 682, in _replace_at
    self._insert_at(i, new_key, value)
  File "/home/dch/.virtualenvs/foo/lib/python3.10/site-packages/tomlkit/container.py", line 412, in _insert_at
    or "\n" in previous_item.trivia.trail
  File "/home/dch/.virtualenvs/foo/lib/python3.10/site-packages/tomlkit/items.py", line 474, in trivia
    return self._trivia
AttributeError: 'Null' object has no attribute '_trivia'. Did you mean: 'trivia'?