GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-130273: Fix traceback color output with unicode characters by grayjk · Pull Request #142529 · python/cpython

Conversation

@grayjk

@grayjk grayjk commented Dec 10, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Account for the display width of unicode characters so that colors and underlining in traceback output is correct

Closes #130273

  • Issue: Traceback colors are shifted when the line contains wide unicode characters #130273

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@python-cla-bot

python-cla-bot Bot commented Dec 10, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Dec 10, 2025
Traceback colors are shifted when the line contains wide unicode characters #130273
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Dec 10, 2025
StanFromIreland
StanFromIreland reviewed Dec 10, 2025
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2025-12-10-15-15-09.gh-issue-130273.iCfiY5.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Dec 11, 2025

Copy link
Copy Markdown
Member

@serhiy-storchaka: Here is a PR about text width and Unicode characters :-)

grayjk reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

grayjk added 3 commits January 28, 2026 17:45
@grayjk
Fix traceback color output with unicode characters
306a690
Closes python#130273
@grayjk
mv news blurb
8edad11
@grayjk
use unicodedata.iter_graphemes
7947033
@grayjk
grayjk force-pushed the issue-130273 branch from 59ca7f0 to 7947033 Compare January 28, 2026 23:05
@grayjk

grayjk commented Jan 28, 2026

Copy link
Copy Markdown
Contributor Author

updated to use @serhiy-storchaka's recently added unicodedata.iter_graphemes

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@grayjk
grayjk requested a review from StanFromIreland January 28, 2026 23:19
@grayjk

grayjk commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

@pablogsal @hauntsaninja as recent reviewers of traceback.py, would you mind taking look

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland

This comment was marked as resolved.

Sign in to view
@grayjk
Merge branch 'main' into issue-130273
e8d23cd
@grayjk

This comment was marked as resolved.

Sign in to view
vstinner
vstinner reviewed Feb 19, 2026
View reviewed changes
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@grayjk
mv wlen/str_width to traceback
467656e
@grayjk
grayjk requested review from ambv, lysnikolaou and pablogsal as code owners February 19, 2026 16:57
@StanFromIreland
StanFromIreland requested a review from serhiy-storchaka March 31, 2026 17:11
@StanFromIreland

StanFromIreland commented Mar 31, 2026

Copy link
Copy Markdown
Member

There are conflicts again I'm afraid, and mypy isn't happy either.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

StanFromIreland
StanFromIreland reviewed Mar 31, 2026
View reviewed changes
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Apr 1, 2026
View reviewed changes
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Library/2025-12-10-15-15-09.gh-issue-130273.iCfiY5.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

This comment was marked as outdated.

Sign in to view
@pablogsal

This comment was marked as outdated.

Sign in to view
@Wulian233

Wulian233 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

@pablogsal You maybe make wrong something :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv mentioned this pull request Apr 7, 2026
gh-130273: Fix incorrectly colored error locations when wide unicode characters exists #130277
Closed
ambv added 2 commits April 7, 2026 12:22
@ambv
Merge branch 'main' into pr-142529
05ad91e
@ambv
Restore _pyrepl.utils.str_width and .wlen; respond to code review
37a4fd9
@ambv
Remove ASCII fast track that was too eager
1318217
@ambv

ambv commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for your PR.

I reverted the move of string-handling utils to traceback, they don't belong there
Now those utils are copied into traceback temporarily so that we can backport the fixes to older bugfix branches (3.13 and 3.14). In main I will do a follow-up change where those utils are moved to string/__init__.py where they belong.

This is because mypy type-checking introduction to the standard library relies on introduction of fully type-annotated libraries. I intend to keep it that way and therefore sprinkling type: ignore is not a solution.

It is now out of scope to format all of traceback.py for 3.15 while string.py is just three small classes and a function (two more functions if we count string.templatelib). When I make this change, I will also undo the unicodedata conditional import shenanigans and use lazy imports. That's also why this will be a main-only change.

There's also a related behavioral change in _display_width that I feel is part of this fix. It introduces handling of pre-existing terminal escape sequences in the exception strings (as well as any stranded ^Z characters but those are admittedly unlikely to be part of tracebacks).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ambv added 3 commits April 7, 2026 13:59
@ambv
Add _zip_display_width fast track suggested by Victor
7b3fa87
@ambv
Move str_width and wlen to the place in the file where they were before
4ddf024
@ambv
derp
f094135
@ambv
ambv requested a review from Copilot April 7, 2026 12:49
Copilot started reviewing on behalf of ambv April 7, 2026 12:50
View session
Copilot AI reviewed Apr 7, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes misaligned color highlighting/underlining in traceback output when the source line contains wide Unicode characters or grapheme clusters, by switching caret/column calculations to use display width rather than raw character offsets.

Changes:

  • Introduces grapheme-aware zipping between source characters and caret markers to keep colored segments aligned with terminal display width.
  • Reworks _display_width() to use _wlen()/_str_width() logic (including CTRL-Z and ANSI escape sequence handling) and adds targeted tests for wide/combining/ASCII edge cases.
  • Adds a NEWS fragment documenting the fix.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Misc/NEWS.d/next/Library/2025-12-10-15-15-09.gh-issue-130273.iCfiY5.rst Announces the traceback color alignment fix for Unicode characters.
Lib/traceback.py Implements grapheme/display-width-aware caret-to-text alignment and updates width calculation helpers.
Lib/test/test_traceback.py Adds regression tests for colorized tracebacks with wide/combining Unicode and ASCII display-width edge cases.
Lib/_pyrepl/utils.py Minor whitespace-only change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/traceback.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ambv
ambv merged commit dfeb160 into python:main Apr 7, 2026
64 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting review label Apr 7, 2026
@ambv ambv added awaiting review needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Apr 7, 2026
@miss-islington-app

miss-islington-app Bot commented Apr 7, 2026

Copy link
Copy Markdown

Thanks @grayjk for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Apr 7, 2026

Copy link
Copy Markdown

Thanks @grayjk for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Apr 7, 2026

Copy link
Copy Markdown

Sorry, @grayjk and @ambv, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker dfeb160bc35f0ba16800d07b85cb11598d1cd307 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned ambv Apr 7, 2026
@miss-islington-app

miss-islington-app Bot commented Apr 7, 2026

Copy link
Copy Markdown

Sorry, @grayjk and @ambv, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker dfeb160bc35f0ba16800d07b85cb11598d1cd307 3.13
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv

ambv commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

There's some trivial conflicts that can be solved here, but the real problem is that unicodedata.iter_graphemes is new for 3.15 and a pure Python reimplementation is close to 200 lines.

WDYT, @serhiy-storchaka, is it worth creating a pure Python version of this segmentation purely for the backports?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv

ambv commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

To help you decide, I created #148218 so you can see what the implementation would look like.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv mentioned this pull request Apr 7, 2026
gh-130273: Add pure Python implementation of unicodedata.iter_graphemes() #148218
Closed
@grayjk
grayjk deleted the issue-130273 branch April 8, 2026 01:39
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@grayjk @ambv
@vstinner @ljfp
pythongh-130273: Fix traceback color output with unicode characters (p…
9e263c6
…ythonGH-142529)

Account for the display width of Unicode characters so that colors and underlining in traceback output is correct.

Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@serhiy-storchaka serhiy-storchaka removed needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@StanFromIreland StanFromIreland StanFromIreland left review comments
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@ambv ambv Awaiting requested review from ambv ambv is a code owner
@serhiy-storchaka serhiy-storchaka Awaiting requested review from serhiy-storchaka

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ambv ambv

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Traceback colors are shifted when the line contains wide unicode characters

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@grayjk @vstinner @StanFromIreland @pablogsal @Wulian233 @ambv @serhiy-storchaka
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.