|
13 | 13 | import _colorize |
14 | 14 |
|
15 | 15 | from contextlib import suppress |
16 | | -from _colorize import get_theme, theme_no_color |
17 | 16 |
|
18 | 17 | __all__ = ['extract_stack', 'extract_tb', 'format_exception', |
19 | 18 | 'format_exception_only', 'format_list', 'format_stack', |
@@ -187,7 +186,10 @@ def format_exception_only(exc, /, value=_sentinel, *, show_group=False, **kwargs |
187 | 186 | def _format_final_exc_line(etype, value, *, insert_final_newline=True, colorize=False): |
188 | 187 | valuestr = _safe_string(value, 'exception') |
189 | 188 | end_char = "\n" if insert_final_newline else "" |
190 | | - theme = (theme_no_color if not colorize else get_theme()).traceback |
| 189 | + if colorize: |
| 190 | + theme = _colorize.get_theme(force_color=True).traceback |
| 191 | + else: |
| 192 | + theme = _colorize.get_theme(force_no_color=True).traceback |
191 | 193 | if value is None or not valuestr: |
192 | 194 | line = f"{theme.type}{etype}{theme.reset}{end_char}" |
193 | 195 | else: |
@@ -534,8 +536,10 @@ def format_frame_summary(self, frame_summary, **kwargs): |
534 | 536 | filename = frame_summary.filename |
535 | 537 | if frame_summary.filename.startswith("<stdin>-"): |
536 | 538 | filename = "<stdin>" |
537 | | - |
538 | | - theme = (theme_no_color if not colorize else get_theme()).traceback |
| 539 | + if colorize: |
| 540 | + theme = _colorize.get_theme(force_color=True).traceback |
| 541 | + else: |
| 542 | + theme = _colorize.get_theme(force_no_color=True).traceback |
539 | 543 | row.append( |
540 | 544 | ' File {}"{}"{}, line {}{}{}, in {}{}{}\n'.format( |
541 | 545 | theme.filename, |
@@ -1373,7 +1377,10 @@ def _format_syntax_error(self, stype, **kwargs): |
1373 | 1377 | """Format SyntaxError exceptions (internal helper).""" |
1374 | 1378 | # Show exactly where the problem was found. |
1375 | 1379 | colorize = kwargs.get("colorize", False) |
1376 | | - theme = (theme_no_color if not colorize else get_theme()).traceback |
| 1380 | + if colorize: |
| 1381 | + theme = _colorize.get_theme(force_color=True).traceback |
| 1382 | + else: |
| 1383 | + theme = _colorize.get_theme(force_no_color=True).traceback |
1377 | 1384 | filename_suffix = '' |
1378 | 1385 | if self.lineno is not None: |
1379 | 1386 | yield ' File {}"{}"{}, line {}{}{}\n'.format( |
|
0 commit comments