Description
PrettyFormat raises ValueError for valid positive widths when indentation consumes all the remaining wrapping width.
Reproduced on current main bdf2bc019b27f10a2bcb3ccf12df6d60597c3b14, CPython 3.13.12, with the frozen development dependencies:
from devtools import PrettyFormat
PrettyFormat(width=11)(['abcdefghijk'])
# ValueError: range() arg 3 must not be zero
class LongRepr:
def __repr__(self):
return 'Custom(value=' + 'x' * 120 + ')'
PrettyFormat(width=12)([[LongRepr()]])
# ValueError: invalid width 0 (must be > 0)The first error also affects bytes and bytearray formatting. The raw-repr failure also occurs at the default width (120) when a non-circular value is deeply nested, so it is not limited to unusually small terminal widths.
_wrap_lines passes self._width - indent_new - 3 to range as its step; _format_raw passes self._width - indent_new to textwrap.wrap. Either can become zero or negative as indentation grows. Formatting should preserve the value and remain usable when the width cannot accommodate both indentation and content. A minimum positive wrapping width would retain the current indentation and avoid the exceptions without changing normal-width output.
This is separate from #161 (syntax highlighting across wrapped repr text) and #177 (circular references); these reproductions use neither highlighting nor circular values.
AI disclosure: OpenAI GPT-6 (Codex) performed the reproduction, analysis and drafting at the account owner's request. No matching narrow/deep-width issue or PR was found in repository searches.
Activity
Preserve raw repr whitespace when wrapping at one character