Repository navigation
PEP 813: keep Expand.ALWAYS through hugging, and support compact in every mode - #6
Merged
ericvsmith merged 1 commit intoOct 23, 2026
Conversation
…very mode A hugged document was always wrapped in a group, so with Expand.ALWAYS a container nested in a hugging object such as a deque could stay on one line. The hugged document now drops its group below the top level, as other containers do with ALWAYS. compact was used only with Expand.NEVER, and was silently ignored with FIT and ALWAYS. It now packs positional items in every mode, using PrettyPrinter's rule: an item whose one-line form fits shares lines with its packable neighbors, and any other item gets lines of its own. With ALWAYS, a non-empty container is never packed. With NEVER, this also fixes a broken container starting partway along a line, so the output now matches PrettyPrinter's, except that a packed line can end at the last column of the width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Two fixes from another round of comparing the implementation with the PEP.
hugandExpand.ALWAYS. A hugged document was always wrapped in a group, so withALWAYSa container nested in a hugging object stayed on one line:[list(range(8)), deque([[1, 2], [3]])]keptdeque([[1, 2], [3]])flat. The hugged document now drops its group below the top level, as other containers already do withALWAYS, so every non-empty nested container expands as the PEP says.compactin every mode.compactwas used only withExpand.NEVER, and was silently ignored withFITandALWAYS, soPrinter(compact=True)did nothing with the defaultexpand. It now packs positional items in every mode, usingPrettyPrinter's rule: an item whose one-line form fits shares lines with its packable neighbors, and any other item gets lines of its own.With
ALWAYS, a non-empty container is never packed. Key/value and keyword items are not packed, as before.This also fixes
NEVERcompact, where a broken container could start partway along a line ([1, 2, [0, 1, 2, 3,). AgainstPrettyPrinter(compact=True)on 3,000 random nested objects, all remaining differences are one boundary case: a packed line may now end at the last column of the width, wherePrettyPrinterreserves room for a', 'after the last item and breaks one item earlier. Our output never goes past the width wherePrettyPrinter's doesn't.Tests: test__pprint, test_pprint, test_collections, test_dataclasses, test_fstring, test_tstring and test_string pass.
🤖 Generated with Claude Code