@@ -467,13 +467,17 @@ def perror(msg: Any, *, end: str = '\n', apply_style: bool = True) -> None:
467
467
final_msg = "{}" .format (msg )
468
468
ansi .ansi_aware_write (sys .stderr , final_msg + end )
469
469
470
- def pwarning (self , msg : Any , * , end : str = '\n ' ) -> None :
471
- """Apply the warning style to a message and print it to sys.stderr
470
+ def pwarning (self , msg : Any , * , end : str = '\n ' , apply_style : bool = True ) -> None :
471
+ """Like perror, but applies ansi.style_warning by default
472
472
473
473
:param msg: message to print (anything convertible to a str with '{}'.format() is OK)
474
474
:param end: string appended after the end of the message, default a newline
475
+ :param apply_style: If True, then ansi.style_warning will be applied to the message text. Set to False in cases
476
+ where the message text already has the desired style. Defaults to True.
475
477
"""
476
- self .perror (ansi .style_warning (msg ), end = end , apply_style = False )
478
+ if apply_style :
479
+ msg = ansi .style_warning (msg )
480
+ self .perror (msg , end = end , apply_style = False )
477
481
478
482
def pexcept (self , msg : Any , * , end : str = '\n ' , apply_style : bool = True ) -> None :
479
483
"""Print Exception message to sys.stderr. If debug is true, print exception traceback if one exists.
@@ -499,7 +503,6 @@ def pexcept(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> Non
499
503
warning = "\n To enable full traceback, run the following command: 'set debug true'"
500
504
final_msg += ansi .style_warning (warning )
501
505
502
- # Set apply_style to False since style has already been applied
503
506
self .perror (final_msg , end = end , apply_style = False )
504
507
505
508
def pfeedback (self , msg : Any , * , end : str = '\n ' ) -> None :
0 commit comments