Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Error on Python 3.13 and newer.
Reproducer
- Run IDLE
- Set a custom
sys.excepthook:
importsysdefhook(*args):returnsys.__excepthook__(*args)sys.excepthook=hook
- Trigger an error which display a traceback, such as accessing a variable which doesn't exist.
Output
>>> osTraceback (most recent call last): File �[35m"/home/vstinner/python/3.13/Lib/idlelib/run.py"�[0m, line �[35m590�[0m, in �[35mruncode�[0m �[31mexec�[0m�[1;31m(code,self.locals)�[0m �[31m~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^^^^�[0m File �[35m"<pyshell#12>"�[0m, line �[35m1�[0m, in �[35m<module>�[0m�[1;35mNameError�[0m:�[35mname 'os' is not defined. Did you forget to import 'os'?�[0m
ANSI sequences to colorize the output are unexpected and makes the output hard to read.
Expected output
>>> osTraceback (most recent call last): File"<pyshell#0>", line1, in<module> osNameError:name 'os' is not defined. Did you forget to import 'os'?
Explanation
In the normal case:
- IDLE replaces
sys.stderrwithio.StringIO()to call the "excepthook". _colorize.can_colorize()returns False.- It works as expected.
Ifsys.excepthook is overridden:
- IDLE replaces sys.stderr with a
idlelib.run.StdOutputFileobject at startup. _colorize.can_colorize()returnsTruebecauseStdOutputFile.isatty()always returnTrue.
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done