Repository navigation
Conversation
Wkhanex
reviewed
Oct 16, 2026
Wkhanex
left a comment
There was a problem hiding this comment.
AI-assisted validation at 29948bb5c60d on Python 3.12.14: I checked front insertion with both 0 and a far-negative index against compact, padded, single-element, commented, and multiline arrays. All ten parsed cases preserved their expected data under tomllib; constructed arrays produced exactly [0, 1, 2]. The 26 array-focused tests passed.
The far-negative insertion is useful to retain alongside insert(0, ...): native list semantics clamp it to the front, so it should take the same displaced-first-element spacing path. I also checked a trailing comment on the former first value, which remained valid after insertion.
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
Inserting at the front of a single-line array leaves the element that used to be first glued to the new comma. This happens for parsed arrays and for arrays built with
item():The new group takes the first element's indent, which is empty in this layout, and the displaced element keeps its empty indent.
Array.insertnow gives the displaced element the same default" "indent that any non-first inserted element already gets, so the result is[0, 1, 2]. Padded ([ 1, 2 ]), multiline and comma-first arrays already set an indent on their first element and render exactly as before. Insertions in the middle or at the end are unaffected.Testing:
test_insert_at_front_of_array_keeps_space_after_commafails on the current master and passes with the change. The full suite passes on Python 3.11 (1203 passed) and 3.9 (1202 passed, 1 skipped), andpre-commit runpasses on the changed files. A before/after comparison of 22 array layouts with inserts at several positions changed only the front-insert cases described above.Agent Drafting Metadata