Skip to content
Prev Previous commit
Next Next commit
use unicodedata.iter_graphemes
  • Loading branch information
grayjk committed Jan 28, 2026
commit 794703397a2490f0cb587df8ce1118ea1fcc0404
17 changes: 4 additions & 13 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,22 +968,13 @@ def setup_positions(expr, force_valid=True):
return None


def _lookahead(iterator, default):
forked = itertools.tee(iterator, 1)[0]
return next(forked, default)


def _zip_display_width(line, carets):
line = itertools.tee(line, 1)[0]
import unicodedata
carets = iter(carets)
for char in line:
for char in unicodedata.iter_graphemes(line):
char = str(char)
char_width = _display_width(char)
next_char = _lookahead(line, "")
if next_char and char_width == _display_width(char + next_char):
next(line)
yield char + next_char, "".join(itertools.islice(carets, char_width))
else:
yield char, "".join(itertools.islice(carets, char_width))
yield char, "".join(itertools.islice(carets, char_width))
Comment thread
ambv marked this conversation as resolved.


Comment thread
ambv marked this conversation as resolved.
def _display_width(line, offset=None):
Expand Down
Loading