Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-128595: Default to stdout isatty for colour detection instead of stderr#128498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Should this be considered a bugfix to backport to 3.13, with its own issue and NEWS, or piggyback ongh-128317 for 3.14 only? |
Issue, NEWS and backport label applied. |
Agree this sounds like a bug to me :) |
Why not check this for stdout and stderr separately? If the traceback is written to terminal, it should be colorized. |
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) |
Yes, except that dynamic value |
Can you extract the code to disable colors as a separated PR and merge it first? |
Sure! Please see PR#128687. |
Now merged, making this PR much simpler. |
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
Uh oh!
There was an error while loading.Please reload this page.
Thanks again for the reviews! Next to update#127877. |
6f167d7
intopython:mainUh oh!
There was an error while loading.Please reload this page.
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 commit6f167d7)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 commit6f167d7)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 the3.13 branch. |
Some build bots are now failing (https://buildbot.python.org/api/v2/logs/12166870/raw_inline):
|
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>
Uh oh!
There was an error while loading.Please reload this page.
As suggested at#128317 (comment), default to checking
stdout
'sisatty
rather thanstderr
's.Also using the
@force_not_colorized_test_class
decorator from#127877 to run some tests without worrying about colour.