FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-118626: Use less red-ish colour for non-error traceback by hugovk · Pull Request #119966 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions Lib/_colorize.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class ANSIColors:
BOLD_BLUE = "\x1b[1;34m"
BOLD_GREEN = "\x1b[1;32m"
BOLD_MAGENTA = "\x1b[1;35m"
BOLD_RED = "\x1b[1;31m"
Expand Down
41 changes: 20 additions & 21 deletions Lib/test/test_traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4503,15 +4503,15 @@ def bar():
e, capture_locals=True
)
lines = "".join(exc.format(colorize=True))
red = _colorize.ANSIColors.RED
boldb = _colorize.ANSIColors.BOLD_BLUE
boldr = _colorize.ANSIColors.BOLD_RED
reset = _colorize.ANSIColors.RESET
self.assertIn("y = " + red + "x['a']['b']" + reset + boldr + "['c']" + reset, lines)
self.assertIn("return " + red + "(lambda *args: foo(*args))" + reset + boldr + "(1,2,3,4)" + reset, lines)
self.assertIn("return (lambda *args: " + red + "foo" + reset + boldr + "(*args)" + reset + ")(1,2,3,4)", lines)
self.assertIn("y = " + boldb + "x['a']['b']" + reset + boldr + "['c']" + reset, lines)
self.assertIn("return " + boldb + "(lambda *args: foo(*args))" + reset + boldr + "(1,2,3,4)" + reset, lines)
self.assertIn("return (lambda *args: " + boldb + "foo" + reset + boldr + "(*args)" + reset + ")(1,2,3,4)", lines)
self.assertIn("return baz2(1,2,3,4)", lines)
self.assertIn("return baz1(1,\n 2,3\n ,4)", lines)
self.assertIn(red + "bar" + reset + boldr + "()" + reset, lines)
self.assertIn(boldb + "bar" + reset + boldr + "()" + reset, lines)

def test_colorized_syntax_error(self):
try:
Expand All @@ -4521,16 +4521,15 @@ def test_colorized_syntax_error(self):
e, capture_locals=True
)
actual = "".join(exc.format(colorize=True))
red = _colorize.ANSIColors.RED
magenta = _colorize.ANSIColors.MAGENTA
boldb = _colorize.ANSIColors.BOLD_BLUE
boldm = _colorize.ANSIColors.BOLD_MAGENTA
boldr = _colorize.ANSIColors.BOLD_RED
reset = _colorize.ANSIColors.RESET
expected = "".join([
f' File {magenta}"<string>"{reset}, line {magenta}1{reset}\n',
f' a {boldr}${reset} b\n',
f' {boldr}^{reset}\n',
f'{boldm}SyntaxError{reset}: {magenta}invalid syntax{reset}\n']
f' File {boldb}"<string>"{reset}, line {boldb}1{reset}\n',
f' a {boldr}${reset} b\n',
f' {boldr}^{reset}\n',
f'{boldm}SyntaxError{reset}: {boldb}invalid syntax{reset}\n']
)
self.assertIn(expected, actual)

Expand All @@ -4548,22 +4547,22 @@ def foo():
exception_print(e)
actual = tbstderr.getvalue().splitlines()

red = _colorize.ANSIColors.RED
boldb = _colorize.ANSIColors.BOLD_BLUE
boldr = _colorize.ANSIColors.BOLD_RED
magenta = _colorize.ANSIColors.MAGENTA
boldm = _colorize.ANSIColors.BOLD_MAGENTA
reset = _colorize.ANSIColors.RESET
lno_foo = foo.__code__.co_firstlineno
expected = ['Traceback (most recent call last):',
f' File {magenta}"{__file__}"{reset}, '
f'line {magenta}{lno_foo+5}{reset}, in {magenta}test_colorized_traceback_is_the_default{reset}',
f' {red}foo{reset+boldr}(){reset}',
f' {red}~~~{reset+boldr}^^{reset}',
f' File {magenta}"{__file__}"{reset}, '
f'line {magenta}{lno_foo+1}{reset}, in {magenta}foo{reset}',
f' {red}1{reset+boldr}/{reset+red}0{reset}',
f' {red}~{reset+boldr}^{reset+red}~{reset}',
f'{boldm}ZeroDivisionError{reset}: {magenta}division by zero{reset}']
f' File {boldb}"{__file__}"{reset}, '
f'line {boldb}{lno_foo+5}{reset}, in {magenta}test_colorized_traceback_is_the_default{reset}',
f' {boldb}foo{reset+boldr}(){reset}',
f' {boldr}~~~{reset+boldr}^^{reset}',
f' File {boldb}"{__file__}"{reset}, '
f'line {boldb}{lno_foo+1}{reset}, in {magenta}foo{reset}',
f' {boldb}1{reset+boldr}/{reset+boldb}0{reset}',
f' {boldr}~{reset+boldr}^{reset+boldr}~{reset}',
f'{boldm}ZeroDivisionError{reset}: {boldb}division by zero{reset}']
self.assertEqual(actual, expected)


Expand Down
16 changes: 8 additions & 8 deletions Lib/traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _format_final_exc_line(etype, value, *, insert_final_newline=True, colorize=
if value is None or not valuestr:
line = f"{ANSIColors.BOLD_MAGENTA}{etype}{ANSIColors.RESET}{end_char}"
else:
line = f"{ANSIColors.BOLD_MAGENTA}{etype}{ANSIColors.RESET}: {ANSIColors.MAGENTA}{valuestr}{ANSIColors.RESET}{end_char}"
line = f"{ANSIColors.BOLD_MAGENTA}{etype}{ANSIColors.RESET}: {ANSIColors.BOLD_BLUE}{valuestr}{ANSIColors.RESET}{end_char}"
else:
if value is None or not valuestr:
line = f"{etype}{end_char}"
Expand Down Expand Up @@ -524,10 +524,10 @@ def format_frame_summary(self, frame_summary, **kwargs):
filename = "<stdin>"
if colorize:
row.append(' File {}"{}"{}, line {}{}{}, in {}{}{}\n'.format(
ANSIColors.MAGENTA,
ANSIColors.BOLD_BLUE,
filename,
ANSIColors.RESET,
ANSIColors.MAGENTA,
ANSIColors.BOLD_BLUE,
frame_summary.lineno,
ANSIColors.RESET,
ANSIColors.MAGENTA,
Expand Down Expand Up @@ -659,8 +659,8 @@ def output_line(lineno):
colorized_line_parts.append(ANSIColors.BOLD_RED + "".join(char for char, _ in caret_group) + ANSIColors.RESET)
colorized_carets_parts.append(ANSIColors.BOLD_RED + "".join(caret for _, caret in caret_group) + ANSIColors.RESET)
elif color == "~":
colorized_line_parts.append(ANSIColors.RED + "".join(char for char, _ in caret_group) + ANSIColors.RESET)
colorized_carets_parts.append(ANSIColors.RED + "".join(caret for _, caret in caret_group) + ANSIColors.RESET)
colorized_line_parts.append(ANSIColors.BOLD_BLUE + "".join(char for char, _ in caret_group) + ANSIColors.RESET)
colorized_carets_parts.append(ANSIColors.BOLD_RED + "".join(caret for _, caret in caret_group) + ANSIColors.RESET)
else:
colorized_line_parts.append("".join(char for char, _ in caret_group))
colorized_carets_parts.append("".join(caret for _, caret in caret_group))
Expand Down Expand Up @@ -1267,10 +1267,10 @@ def _format_syntax_error(self, stype, **kwargs):
if self.lineno is not None:
if colorize:
yield ' File {}"{}"{}, line {}{}{}\n'.format(
ANSIColors.MAGENTA,
ANSIColors.BOLD_BLUE,
self.filename or "<string>",
ANSIColors.RESET,
ANSIColors.MAGENTA,
ANSIColors.BOLD_BLUE,
self.lineno,
ANSIColors.RESET,
)
Expand Down Expand Up @@ -1332,7 +1332,7 @@ def _format_syntax_error(self, stype, **kwargs):
ANSIColors.BOLD_MAGENTA,
stype,
ANSIColors.RESET,
ANSIColors.MAGENTA,
ANSIColors.BOLD_BLUE,
msg,
ANSIColors.RESET,
filename_suffix)
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use less red-ish colour for non-error traceback. Patch by Hugo van Kemenade.

Back | FazBrowse Home | New Git URL