Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
from tomlkit.items import item as _item


_NOT_SET = object()


def _is_empty_aot(item: Item) -> bool:
"""Whether ``item`` is an array of tables with no elements left."""
return isinstance(item, AoT) and not item.body
Expand Down Expand Up @@ -592,53 +589,6 @@ def remove(self, key: Key | str) -> Container:

return self

def _insert_after(
self, key: Key | str, other_key: Key | str, item: Any
) -> Container:
if key is None:
raise ValueError("Key cannot be null in insert_after()")

if key not in self:
raise NonExistentKey(key)

if not isinstance(key, Key):
key = SingleKey(key)

if not isinstance(other_key, Key):
other_key = SingleKey(other_key)

item = _item(item)

idx = self._map[key]
# Insert after the max index if there are many.
if isinstance(idx, tuple):
idx = max(idx)
current_item = self._body[idx][1]
if "\n" not in current_item.trivia.trail:
current_item.trivia.trail += "\n"

# Increment indices after the current index
for k, v in self._map.items():
if isinstance(v, tuple):
new_indices = []
for v_ in v:
if v_ > idx:
v_ = v_ + 1

new_indices.append(v_)

self._map[k] = tuple(new_indices)
elif v > idx:
self._map[k] = v + 1

self._map[other_key] = idx + 1
self._body.insert(idx + 1, (other_key, item))

if key is not None:
dict.__setitem__(self, other_key.key, item.value)

return self

def _insert_at(self, idx: int, key: Key | str, item: Any) -> Container:
if idx > len(self._body) - 1:
raise ValueError(f"Unable to insert at position {idx}")
Expand Down
Loading