File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -970,6 +970,8 @@ def style(
970
970
:param overline: apply the overline style if True. Defaults to False.
971
971
:param strikethrough: apply the strikethrough style if True. Defaults to False.
972
972
:param underline: apply the underline style if True. Defaults to False.
973
+ :raises: TypeError if fg isn't None or a subclass of FgColor
974
+ :raises: TypeError if bg isn't None or a subclass of BgColor
973
975
:return: the stylized string
974
976
"""
975
977
# List of strings that add style
@@ -980,10 +982,14 @@ def style(
980
982
981
983
# Process the style settings
982
984
if fg is not None :
985
+ if not isinstance (fg , FgColor ):
986
+ raise TypeError ("fg must be a subclass of FgColor" )
983
987
additions .append (fg )
984
988
removals .append (Fg .RESET )
985
989
986
990
if bg is not None :
991
+ if not isinstance (bg , BgColor ):
992
+ raise TypeError ("bg must a subclass of BgColor" )
987
993
additions .append (bg )
988
994
removals .append (Bg .RESET )
989
995
Original file line number Diff line number Diff line change @@ -58,6 +58,17 @@ def test_style_bg(bg_color):
58
58
assert ansi .style (base_str , bg = bg_color ) == ansi_str
59
59
60
60
61
+ # noinspection PyTypeChecker
62
+ def test_style_invalid_types ():
63
+ # Use a BgColor with fg
64
+ with pytest .raises (TypeError ):
65
+ ansi .style ('test' , fg = ansi .Bg .BLUE )
66
+
67
+ # Use a FgColor with bg
68
+ with pytest .raises (TypeError ):
69
+ ansi .style ('test' , bg = ansi .Fg .BLUE )
70
+
71
+
61
72
def test_style_bold ():
62
73
base_str = HELLO_WORLD
63
74
ansi_str = ansi .TextStyle .INTENSITY_BOLD + base_str + ansi .TextStyle .INTENSITY_NORMAL
@@ -236,7 +247,6 @@ def test_sequence_str_building(ansi_sequence):
236
247
],
237
248
)
238
249
def test_rgb_bounds (r , g , b , valid ):
239
-
240
250
if valid :
241
251
ansi .RgbFg (r , g , b )
242
252
ansi .RgbBg (r , g , b )
You can’t perform that action at this time.
0 commit comments