Uh oh!
There was an error while loading. Please reload this page.
gh-128595: Default to stdout isatty for colour detection instead of stderr - #128498
Conversation
hugovk
commented
Jan 4, 2025
Should this be considered a bugfix to backport to 3.13, with its own issue and NEWS, or piggyback on gh-128317 for 3.14 only? |
erlend-aasland
commented
Jan 5, 2025
hugovk
commented
Jan 7, 2025
Issue, NEWS and backport label applied. |
zanieb
commented
Jan 7, 2025
Agree this sounds like a bug to me :) |
serhiy-storchaka
commented
Jan 8, 2025
Why not check this for stdout and stderr separately? If the traceback is written to terminal, it should be colorized. |
hugovk
commented
Jan 8, 2025
For example, something like this? -def can_colorize() -> bool:+def can_colorize(file=sys.stdout) -> bool:
if not sys.flags.ignore_environment:
if os.environ.get("PYTHON_COLORS") == "0":
return False
@@ -49,7 +49,7 @@ def can_colorize() -> bool:
if os.environ.get("TERM") == "dumb":
return False
- if not hasattr(sys.stdout, "fileno"):+ if not hasattr(file, "fileno"):
return False
if sys.platform == "win32":
@@ -62,6 +62,6 @@ def can_colorize() -> bool:
return False
try:
- return os.isatty(sys.stdout.fileno())+ return os.isatty(file.fileno())
except io.UnsupportedOperation:
return sys.stdout.isatty()And then places like def _print_exception_bltin(exc, /):
file = sys.stderr if sys.stderr is not None else sys.__stderr__
- colorize = _colorize.can_colorize()+ colorize = _colorize.can_colorize(file=file)
return print_exception(exc, limit=BUILTIN_EXCEPTION_LIMIT, file=file, colorize=colorize) |
serhiy-storchaka
commented
Jan 8, 2025
Yes, except that dynamic value |
vstinner
commented
Jan 9, 2025
Can you extract the code to disable colors as a separated PR and merge it first? |
hugovk
commented
Jan 9, 2025
Sure! Please see PR #128687. |
hugovk
commented
Jan 13, 2025
Now merged, making this PR much simpler. |
serhiy-storchaka
commented
Jan 13, 2025
Please implement what was discussed above. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
Uh oh!
There was an error while loading. Please reload this page.
hugovk
commented
Jan 20, 2025
Thanks again for the reviews! Next to update #127877. |
Thanks @hugovk for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @hugovk, I could not cleanly backport this to |
… instead of stderr (pythonGH-128498) (cherry picked from commit 6f167d7) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
… instead of stderr (pythonGH-128498) (cherry picked from commit 6f167d7) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
GH-129057 is a backport of this pull request to the 3.13 branch. |
picnixz
commented
Jan 20, 2025
Some build bots are now failing (https://buildbot.python.org/api/v2/logs/12166870/raw_inline):
|
hugovk
commented
Jan 20, 2025
Please see PR #129070 for a fix. |
…d of stderr (python#128498) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
As suggested at #128317 (comment), default to checking
stdout'sisattyrather thanstderr's.Also using the
@force_not_colorized_test_classdecorator from #127877 to run some tests without worrying about colour.