Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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
hugovk commentedJan 4, 2025
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? |
erlend-aasland commentedJan 5, 2025
hugovk commentedJan 7, 2025
Issue, NEWS and backport label applied. |
zanieb commentedJan 7, 2025
Agree this sounds like a bug to me :) |
serhiy-storchaka commentedJan 8, 2025
Why not check this for stdout and stderr separately? If the traceback is written to terminal, it should be colorized. |
hugovk commentedJan 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 commentedJan 8, 2025
Yes, except that dynamic value |
vstinner commentedJan 9, 2025
Can you extract the code to disable colors as a separated PR and merge it first? |
hugovk commentedJan 9, 2025
Sure! Please see PR#128687. |
hugovk commentedJan 13, 2025
Now merged, making this PR much simpler. |
serhiy-storchaka commentedJan 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>
vstinner left a comment
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.
hugovk commentedJan 20, 2025
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. |
picnixz commentedJan 20, 2025
Some build bots are now failing (https://buildbot.python.org/api/v2/logs/12166870/raw_inline):
|
hugovk commentedJan 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>
Uh oh!
There was an error while loading.Please reload this page.
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.