Bug 2325502 - python3-idle not dealing with Python3.13 interpreter colors
Summary: python3-idle not dealing with Python3.13 interpreter colors
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: python3.13
Version: 41
Hardware: Unspecified
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Python Maintainers
QA Contact:
URL: https://discussion.fedoraproject.org/...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-11-12 14:52 UTC by Wolfgang Maier
Modified: 2025-02-26 13:07 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2025-02-26 13:07:49 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github python cpython issues 127060 0 None open IDLE displays ANSI sequences in tracebacks when sys.excepthook is customized 2024-12-04 13:41:08 UTC
Github python cpython pull 128052 0 None Merged [3.13] gh-127060: Disable traceback colors in IDLE (GH-128028) 2025-01-06 13:26:00 UTC

Description Wolfgang Maier 2024-11-12 14:52:08 UTC
Python 3.13 introduced the new interactive interpreter colors (https://docs.python.org/3/using/cmdline.html#controlling-color).
It seems IDLE3 is not yet prepared to handle these and emitshard to read plain text with ANSI color controls in it instead.


Reproducible: Always

Steps to Reproduce:
1. Open IDLE3
2. try to run: os.path (just an example, any other error that triggers use of interpreter colors will also do)
3. observe the mal-formatted error message
Actual Results:  
Traceback (most recent call last):
  File e[35m"/usr/lib64/python3.13/idlelib/run.py"e[0m, line e[35m590e[0m, in e[35mruncodee[0m
    e[31mexece[0me[1;31m(code, self.locals)e[0m
    e[31m~~~~e[0me[1;31m^^^^^^^^^^^^^^^^^^^e[0m
  File e[35m"<pyshell#0>"e[0m, line e[35m1e[0m, in e[35m<module>e[0m
e[1;35mNameErrore[0m: e[35mname 'os' is not defined. Did you forget to import 'os'?e[0m


Expected Results:  
Traceback (most recent call last):
  File "/usr/lib64/python3.13/idlelib/run.py", line 590, in runcode
    exec(code, self.locals)
    ~~~~^^^^^^^^^^^^^^^^^^^
  File "<pyshell#0>", line 1, in <module>
NameError: name 'os' is not defined. Did you forget to import 'os'?

A simple fix is to pass PYTHON_COLORS=0 to idle through its .desktop file.

Comment 1 Miro Hrončok 2024-11-12 15:09:55 UTC
I can reproduce this with Python 3.13.

It is fixed in Python 3.14.0a1.

Comment 2 Miro Hrončok 2024-11-12 15:30:42 UTC
When I build Python 3.13.0 from git source, I cannot reproduce this :/

Comment 3 Miro Hrončok 2024-11-13 11:52:54 UTC
When I build Python 3.13.0 from our RPM, I can still reproduce this.

Comment 4 Victor Stinner 2024-11-20 14:36:32 UTC
IDLE has a different code path depending on sys.excepthook. On Fedora, ABRT installs a special hook in sys.excepthook.

(A) ABRT case:

* IDLE replaces sys.stderr with a idlelib.run.StdOutputFile object at startup.
* _colorize.can_colorize() returns True because StdOutputFile.isatty() always return True.

(B) Default case:

* IDLE replaces sys.stderr with io.StringIO() to call the "excepthook".
* _colorize.can_colorize() returns False.

ABRT comes python3-abrt-addon package, main files:

* /usr/lib/python3.13/site-packages/abrt3.pth
* /usr/lib/python3.13/site-packages/abrt_exception_handler3.py

I'm not sure why IDLE StdOutputFile pretends to be a TTY, whereas it's not.

Comment 5 Victor Stinner 2024-12-04 13:41:44 UTC
I reported the issue to Python upstream: https://github.com/python/cpython/issues/127060

Comment 6 Victor Stinner 2024-12-18 09:40:14 UTC
> I reported the issue to Python upstream: https://github.com/python/cpython/issues/127060

I fixed the issue. The 3.13 fix: https://github.com/python/cpython/commit/f8b4e20137b5c5d1e99cbf6c8f35f7041785b4c1. The fix will be part of the next Python 3.13 release (3.13.2, scheduled at 2025-02-04).

Comment 7 Victor Stinner 2024-12-18 09:41:14 UTC
> A simple fix is to pass PYTHON_COLORS=0 to idle through its .desktop file.

Another workaround is to set TERM environment variable to "dumb" when running IDLE.

Comment 8 Miro Hrončok 2025-01-06 13:26:00 UTC
This was fixed in https://github.com/python/cpython/pull/128052 -- it did not make it into 3.13.1. We can backport it if needed.


Note You need to log in before you can comment on or make changes to this bug.