Fix Array.__delitem__ corrupting rendered output on slice deletion - #599
Open
Fries-tempura wants to merge 1 commit into
Open
Fix Array.__delitem__ corrupting rendered output on slice deletion#599Fries-tempura wants to merge 1 commit into
Fries-tempura wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Array.__delitem__keeps the in-memory list and the rendered value groups in sync, but for slice deletions it recomputes which rendered positions to drop with:This mishandles ordinary slices:
stop == 0(a[:0]):0 or lengthevaluates tolength, so a no-op deletion removes every rendered element.a[-1:]→range(-1, length), anda[:-1]→range(0, -1)(empty, removes nothing).list.__delitem__handles the slice correctly, so the list contents stay right, butas_string()/dumps()silently disagree with them:list(arr)arr.as_string()del arr[:0][1, 2, 3][][1, 2, 3]del arr[-1:][1, 2][][1, 2]del arr[:-1][3][1, 2, 3][3]Fix: use
slice.indices(length), which resolvesNone, negative, and out-of-range bounds exactly the waylist.__delitem__does, so the removed render positions always match the list.Tests: added
test_array_slice_deletion_keeps_render_in_synccoveringa[:0],a[-1:], anda[:-1]. Fulltests/test_items.pypasses (87 passed).Agent Drafting Metadata
main. The one-line fix and the regression test were drafted with the agent and verified locally — the repro fails before the change andtests/test_items.pypasses (87 passed) after. Reviewed by the submitter before opening.