Skip to content

Commit b29c9b9

Browse files
committed
Fix WASI test failures
1 parent 252dfa0 commit b29c9b9

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

Lib/_colorize.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,13 @@ def can_colorize(*, file: IO[str] | IO[bytes] | None = None) -> bool:
213213
theme_no_color = default_theme.no_colors()
214214

215215

216-
def get_theme(*, tty_file: IO[str] | IO[bytes] | None = None) -> Theme:
217-
if can_colorize(file=tty_file):
216+
def get_theme(
217+
*,
218+
tty_file: IO[str] | IO[bytes] | None = None,
219+
force_color: bool = False,
220+
force_no_color: bool = False,
221+
) -> Theme:
222+
if force_color or (not force_no_color and can_colorize(file=tty_file)):
218223
return _theme
219224
return theme_no_color
220225

Lib/_pyrepl/reader.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,7 @@ def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
492492

493493
if self.can_colorize:
494494
t = THEME()
495-
prompt = (
496-
f"{t.prompt}"
497-
f"{prompt}"
498-
f"{t.reset}"
499-
)
495+
prompt = f"{t.prompt}{prompt}{t.reset}"
500496
return prompt
501497

502498
def push_input_trans(self, itrans: input.KeymapTranslator) -> None:

Lib/traceback.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import _colorize
1414

1515
from contextlib import suppress
16-
from _colorize import get_theme, theme_no_color
1716

1817
__all__ = ['extract_stack', 'extract_tb', 'format_exception',
1918
'format_exception_only', 'format_list', 'format_stack',
@@ -187,7 +186,10 @@ def format_exception_only(exc, /, value=_sentinel, *, show_group=False, **kwargs
187186
def _format_final_exc_line(etype, value, *, insert_final_newline=True, colorize=False):
188187
valuestr = _safe_string(value, 'exception')
189188
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
191193
if value is None or not valuestr:
192194
line = f"{theme.type}{etype}{theme.reset}{end_char}"
193195
else:
@@ -534,8 +536,10 @@ def format_frame_summary(self, frame_summary, **kwargs):
534536
filename = frame_summary.filename
535537
if frame_summary.filename.startswith("<stdin>-"):
536538
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
539543
row.append(
540544
' File {}"{}"{}, line {}{}{}, in {}{}{}\n'.format(
541545
theme.filename,
@@ -1373,7 +1377,10 @@ def _format_syntax_error(self, stype, **kwargs):
13731377
"""Format SyntaxError exceptions (internal helper)."""
13741378
# Show exactly where the problem was found.
13751379
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
13771384
filename_suffix = ''
13781385
if self.lineno is not None:
13791386
yield ' File {}"{}"{}, line {}{}{}\n'.format(

0 commit comments

Comments
 (0)