Skip to content

Commit bb90f89

Browse files
committed
Default to stdout isatty for colour detection instead of stderr
1 parent ab76e1b commit bb90f89

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Lib/_colorize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def can_colorize() -> bool:
4949
if os.environ.get("TERM") == "dumb":
5050
return False
5151

52-
if not hasattr(sys.stderr, "fileno"):
52+
if not hasattr(sys.stdout, "fileno"):
5353
return False
5454

5555
if sys.platform == "win32":
@@ -62,6 +62,6 @@ def can_colorize() -> bool:
6262
return False
6363

6464
try:
65-
return os.isatty(sys.stderr.fileno())
65+
return os.isatty(sys.stdout.fileno())
6666
except io.UnsupportedOperation:
67-
return sys.stderr.isatty()
67+
return sys.stdout.isatty()

Lib/test/test_code_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from textwrap import dedent
66
from contextlib import ExitStack
77
from unittest import mock
8-
from test.support import import_helper
9-
8+
from test.support import force_not_colorized_test_class, import_helper
109

1110
code = import_helper.import_module('code')
1211

@@ -30,6 +29,7 @@ def mock_sys(self):
3029
del self.sysmod.ps2
3130

3231

32+
@force_not_colorized_test_class
3333
class TestInteractiveConsole(unittest.TestCase, MockSys):
3434
maxDiff = None
3535

Lib/test/test_traceback.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from test.support.os_helper import TESTFN, unlink
2222
from test.support.script_helper import assert_python_ok, assert_python_failure
2323
from test.support.import_helper import forget
24-
from test.support import force_not_colorized
24+
from test.support import force_not_colorized, force_not_colorized_test_class
2525

2626
import json
2727
import textwrap
@@ -1712,6 +1712,7 @@ def f():
17121712

17131713

17141714
@requires_debug_ranges()
1715+
@force_not_colorized_test_class
17151716
class PurePythonTracebackErrorCaretTests(
17161717
PurePythonExceptionFormattingMixin,
17171718
TracebackErrorLocationCaretTestBase,
@@ -1725,6 +1726,7 @@ class PurePythonTracebackErrorCaretTests(
17251726

17261727
@cpython_only
17271728
@requires_debug_ranges()
1729+
@force_not_colorized_test_class
17281730
class CPythonTracebackErrorCaretTests(
17291731
CAPIExceptionFormattingMixin,
17301732
TracebackErrorLocationCaretTestBase,
@@ -1736,6 +1738,7 @@ class CPythonTracebackErrorCaretTests(
17361738

17371739
@cpython_only
17381740
@requires_debug_ranges()
1741+
@force_not_colorized_test_class
17391742
class CPythonTracebackLegacyErrorCaretTests(
17401743
CAPIExceptionFormattingLegacyMixin,
17411744
TracebackErrorLocationCaretTestBase,
@@ -2149,10 +2152,12 @@ def test_print_exception_bad_type_python(self):
21492152
boundaries = re.compile(
21502153
'(%s|%s)' % (re.escape(cause_message), re.escape(context_message)))
21512154

2155+
@force_not_colorized_test_class
21522156
class TestTracebackFormat(unittest.TestCase, TracebackFormatMixin):
21532157
pass
21542158

21552159
@cpython_only
2160+
@force_not_colorized_test_class
21562161
class TestFallbackTracebackFormat(unittest.TestCase, TracebackFormatMixin):
21572162
DEBUG_RANGES = False
21582163
def setUp(self) -> None:
@@ -2940,6 +2945,7 @@ def f():
29402945
self.assertEqual(report, expected)
29412946

29422947

2948+
@force_not_colorized_test_class
29432949
class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
29442950
#
29452951
# This checks reporting through the 'traceback' module, with both
@@ -2956,6 +2962,7 @@ def get_report(self, e):
29562962
return s
29572963

29582964

2965+
@force_not_colorized_test_class
29592966
class CExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
29602967
#
29612968
# This checks built-in reporting by the interpreter.

0 commit comments

Comments
 (0)