Repository navigation
Conversation
Fixes samuelcolvin#178. Clamp the remaining wrapping budget to one character for strings, bytes, bytearrays and raw reprs; preserve normal-width behavior and indentation. AI assistance: OpenAI GPT-6 (Codex), authorized by the account owner. Prompt summary: reproduce positive-width and deeply nested formatting crashes, add regression coverage, and verify the frozen toolchain tests, lint and independent reviews.
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
Keep spaces and tabs as individual content lines when indentation exhausts the wrapping width. Leave normal-width textwrap output unchanged. Add exact-content regression coverage for narrow and deep nesting, with and without highlighting. Refs samuelcolvin#178 AI assistance: OpenAI GPT-6 (Codex) performed analysis, implementation and validation at the account owner's request.
This branch has not been deployed
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.
Fixes #178.
Formatting can raise
ValueErrorwhen a valid positive width is consumed by indentation. String/byte wrapping gets a zerorangestep, and raw repr wrapping givestextwrapa non-positive width. Deep nesting can hit the latter even at the default width.Keep the remaining wrapping budget at least one character in both paths. When raw reprs wrap at one character, retain every space and tab as content instead of letting
textwrapdiscard or normalize it. Preserve indentation and normal-width wrapping. This does not change syntax-highlighting behavior in #161 or circular-reference handling in #177.Validation using the frozen
uv.lock, CPython 3.13.12 on macOS:d5c1172and pass after the follow-up. Covers zero, negative and one-character remaining widths, spaces/tabs and highlighting on/off.env -u NO_COLOR CONTEXT=macOS-py3.13-with-extras COLUMNS=150 UV_FROZEN=1 uv run coverage run -m pytest: 185 passed, 4 skipped.UV_FROZEN=1 make lint: Ruff format/check and strict basedpyright all pass, 0 type errors/warnings.The execution environment sets
NO_COLOR=1, which makes an unrelated existingtest_print_is_ttyfail on both the base and this branch. It passes with that variable unset; no ANSI code/test was changed to hide it. Other Python/OS combinations have not been run locally. Upstream CI for the original head passed; a new run is required for the follow-up commit and is not represented as passing by local results.AI assistance: OpenAI GPT-6 (Codex) performed reproduction, implementation, tests, drafting and independent agent reviews at the account owner's request.
Summary by cubic
Fixes a
ValueErrorcrash when indentation exhausts the available formatting width. String/byte wrapping could get a zero-widthrangestep, and raw repr wrapping could pass a non-positive width totextwrap; deep nesting triggered the latter even at the default width.Both wrapping paths now clamp the remaining budget to at least one character. When raw reprs wrap at one character, spaces and tabs are kept as their own lines so
textwrapcannot drop or normalize them. Indentation, payloads, and normal-width wrapping are preserved; highlighting behavior is unchanged.Tests
Written for commit c89e54c. Summary will update on new commits.