Skip to content

Commit 47f74a2

Browse files
Chnge color to CYAN, refactor coloring
1 parent c0fb9bc commit 47f74a2

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

Lib/_colorize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class Syntax(ThemeSection):
327327
class Traceback(ThemeSection):
328328
type: str = ANSIColors.BOLD_MAGENTA
329329
message: str = ANSIColors.MAGENTA
330-
note: str = ANSIColors.MAGENTA
330+
note: str = ANSIColors.CYAN
331331
filename: str = ANSIColors.MAGENTA
332332
line_no: str = ANSIColors.MAGENTA
333333
frame: str = ANSIColors.MAGENTA

Lib/test/test_traceback.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5318,10 +5318,10 @@ def foo():
53185318
exc = traceback.TracebackException.from_exception(e)
53195319

53205320
lines = "".join(exc.format(colorize=True))
5321-
magenta = colors["m"]
5321+
note = colors["n"]
53225322
reset = colors["z"]
5323-
self.assertIn(magenta + "First note" + reset, lines)
5324-
self.assertIn(magenta + "Second note" + reset, lines)
5323+
self.assertIn(note + "First note" + reset, lines)
5324+
self.assertIn(note + "Second note" + reset, lines)
53255325

53265326
def test_colorized_syntax_error(self):
53275327
try:

Lib/traceback.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,11 @@ def _display_width(line, offset=None):
993993
)
994994

995995

996+
def _format_note(note, indent, theme):
997+
for l in note.split('\n'):
998+
yield f"{indent}{theme.note}{l}{theme.reset}\n"
999+
1000+
9961001

9971002
class _ExceptionPrintContext:
9981003
def __init__(self):
@@ -1323,9 +1328,10 @@ def format_exception_only(self, *, show_group=False, _depth=0, **kwargs):
13231328
):
13241329
for note in self.__notes__:
13251330
note = _safe_string(note, 'note')
1326-
yield from [indent + theme.note + l + theme.reset + '\n' for l in note.split('\n')]
1331+
yield from _format_note(note, indent, theme)
13271332
elif self.__notes__ is not None:
1328-
yield indent + theme.note + "{}".format(_safe_string(self.__notes__, '__notes__', func=repr)) + theme.reset + "\n"
1333+
note = _safe_string(self.__notes__, '__notes__', func=repr)
1334+
yield from _format_note(note, indent, theme)
13291335

13301336
if self.exceptions and show_group:
13311337
for ex in self.exceptions:

0 commit comments

Comments
 (0)