Preserve end-of-line comments on previous entries when removing dependencies#18557
Merged
zanieb merged 2 commits intoastral-sh:mainfrom Mar 19, 2026
Merged
Conversation
1d64c27 to
fb6ebb1
Compare
When removing a dependency from `pyproject.toml`, end-of-line comments on the previous dependency line were being lost. This happened because `toml_edit` stores such comments in the prefix of the *next* array item. When that item was removed, the comment was discarded. Before removing items, transfer any comments from a removed item's prefix to the next remaining item's prefix, or to the array trailing if no remaining item follows. Closes astral-sh#18555 https://claude.ai/code/session_01Q7gJr2bNJBKevDQZh7MDU9
fb6ebb1 to
9ec4bd8
Compare
zanieb
commented
Mar 19, 2026
zanieb
commented
Mar 19, 2026
zanieb
commented
Mar 19, 2026
woodruffw
approved these changes
Mar 19, 2026
6b520ef to
c3147c1
Compare
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.
When a dependency is removed,
toml_editstores any trailing comments in the prefix of the next item. Our implementation did not account for this, causing trailing comments on a dependency to be dropped when the subsequent item is removed.For example, when removing
requestsfrom:With this fix, the comment is preserved.
Closes #18555