-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IDLE displays ANSI sequences in tracebacks when sys.excepthook is customized #127060
Comments
IDLE StdOutputFile.isatty() now returns False instead of True.
On Windows, 3.14.0a1 install or fresh build, I do not see this when running from editor.
After entering at prompt, the only differences are that the file is I do see the code on macOS, so I presume you are using mac or linux. IDLE normally calls print_exception, which call a function to rid tracebacks of IDLE artifacts. When sys.excepthook is changed from sys.excepthook, the custom hook has to do this if desired. The absence of interactive code lines, such as I have thought about converting IDLE always replaces the run process stderr with StdOutputfile. Normally, print_exception is called. After printing the traceback created by python while stderr is bound to an StdOutput file, it calls get_message_line to get SomeException: . For Attribute and Name errors, it temporarily replaces stderr to get the 'Did you mean' hints. (When hints are added for other exception classes, they should be added to the list.) This temporary replacement cannot affect the presence of color codes in the traceback itself. The sys.stdxxx bindings are visible to user code. Changing an attribute might break the intended behavior of existing code. |
Right, I'm on Linux. I expected the behavior to be the same on Windows. On Fedora, the ABRT service installs a custom So this IDLE bug is always reproduced on Fedora without having to install a custom excepthook manually, see: https://bugzilla.redhat.com/show_bug.cgi?id=2325502 |
Oh, I forgot that on Windows Python doesn't use ANSI sequences, but control directly the console using the Windows API. So right, Windows is not affected by this issue. |
Error on Python 3.13 and newer.
Reproducer
sys.excepthook
:Output
ANSI sequences to colorize the output are unexpected and makes the output hard to read.
Expected output
Explanation
In the normal case:
sys.stderr
withio.StringIO()
to call the "excepthook"._colorize.can_colorize()
returns False.If
sys.excepthook
is overridden:idlelib.run.StdOutputFile
object at startup._colorize.can_colorize()
returnsTrue
becauseStdOutputFile.isatty()
always returnTrue
.Linked PRs
The text was updated successfully, but these errors were encountered: