Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

IDLE displays ANSI sequences in tracebacks when sys.excepthook is customized #127060

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-IDLEtype-bugAn unexpected behavior, bug, or error
@vstinner

Description

@vstinner

Error on Python 3.13 and newer.

Reproducer

  • Run IDLE
  • Set a customsys.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 replacessys.stderr withio.StringIO() to call the "excepthook".
  • _colorize.can_colorize() returns False.
  • It works as expected.

Ifsys.excepthook is overridden:

  • IDLE replaces sys.stderr with aidlelib.run.StdOutputFile object at startup.
  • _colorize.can_colorize() returnsTrue becauseStdOutputFile.isatty() always returnTrue.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-IDLEtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp