Repository navigation
Conversation
OutOfOrderTableProxy maps each key to positions in self._tables, but
_remove_table took a table out of that list without shifting the later
positions, so a second delete through the same proxy indexed the wrong
table or ran past the end:
tool = doc["tool"]; del tool["black"]; del tool["ruff"] # IndexError
Remove the table by identity and shift the later positions down.
Wkhanex
left a comment
There was a problem hiding this comment.
I exercised all six deletion orders with three out-of-order tool subtables that had identical contents, retaining the same proxy throughout. Deleting two keys, replacing the remaining key and clearing the proxy all worked: 18 standalone cases passed, with the unrelated project/other tables preserved.
Checking equal-valued fragments is useful here because list.remove could previously select the wrong table by equality. I validated the serialized remaining document with stdlib tomllib and checked the in-memory result separately; clearing retained an empty parent mapping in memory while removing its subtables from the text.
I used Python 3.12.14 against commit ae55098. These were focused checks, not a full-suite run.
Summary
Deleting two keys through the same out-of-order table proxy raises or silently does nothing:
With
[tool.a],[tool.b]and[tool.c]split by other tables,clear()returns but leaves[tool.b]and[tool.c]in the output._tables_mapholds positions inself._tables, and_remove_tableremoved the table withlist.removewithout shifting the later positions (list.removealso compares by equality, so it could take an equal empty table). It now removes the table by identity and shifts the later positions down by one.test_delete_keys_through_the_same_out_of_order_tablefails on master; dropping the shift or shifting the wrong side fails it too.pytest tests(1,069 passed) andpre-commit runon the changed files pass.Agent Drafting Metadata