Skip to content

Conversation

@pjkundert
Copy link
Contributor

The wcwidth based "wide character" support is badly broken.

By reverting the code related to ANSI codes recently added (early to mid 2024), the wide character tests resume working.

I reviewed the base code from the Python textwrap module (including versions prior to the hyphen support), and compared these to the pre-ANSI code in the _handle_long_words function:

https://github.com/python/cpython/blob/06c779474c7f53bccb8ebf42c66e73b2488bf488/Lib/textwrap.py#L197

I came to the conclusion that the ANSI support here was totally broken (didn't use self._len, went into infinite loops in 2 places, etc.), so needed to be reverted and re-thought.

After this, all the wide character tests resumed working.

@pjkundert pjkundert marked this pull request as draft October 27, 2025 02:46
@pjkundert
Copy link
Contributor Author

This is still not correct; Switching to a Work In Progress

o Tests pass with/without wcwidth module installed
o Include some linting changes
@pjkundert
Copy link
Contributor Author

OK, this works now with/without wcwidth installed. Turns out it was mostly just that self._len wasn't being used.

However, the code used to go into an infinite loop because of a dangerous exit condition in the chunk length calculation; I fixed that to use a limited range instead.

@pjkundert pjkundert marked this pull request as ready for review October 27, 2025 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant