-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IDLEtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Error on Python 3.13 and newer.
Reproducer
- Run IDLE
- Set a custom
sys.excepthook:
import sys
def hook(*args): return sys.__excepthook__(*args)
sys.excepthook=hook- Trigger an error which display a traceback, such as accessing a variable which doesn't exist.
Output
>>> os
Traceback (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'?�[0mANSI sequences to colorize the output are unexpected and makes the output hard to read.
Expected output
>>> os
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
os
NameError: 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.
If sys.excepthook is overridden:
- IDLE replaces sys.stderr with a
idlelib.run.StdOutputFileobject at startup. _colorize.can_colorize()returnsTruebecauseStdOutputFile.isatty()always returnTrue.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-IDLEtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done