Skip to content

Commit f591319

Browse files
Make __get_ansi_code private
1 parent 64e5b95 commit f591319

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pylint/reporters/text.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MessageStyle(NamedTuple):
3737
style: tuple[str, ...] = ()
3838
"""Tuple of style strings (see `ANSI_COLORS` for available values)."""
3939

40-
def _get_ansi_code(self) -> str:
40+
def __get_ansi_code(self) -> str:
4141
"""Return ANSI escape code corresponding to color and style.
4242
4343
:raise KeyError: if a nonexistent color or style identifier is given
@@ -55,6 +55,16 @@ def _get_ansi_code(self) -> str:
5555
return ANSI_PREFIX + ";".join(ansi_code) + ANSI_END
5656
return ""
5757

58+
def _colorize_ansi(self, msg: str) -> str:
59+
if self.color is None and len(self.style) == 0:
60+
# If both color and style are not defined, then leave the text as is.
61+
return msg
62+
escape_code = self.__get_ansi_code()
63+
# If invalid (or unknown) color, don't wrap msg with ANSI codes
64+
if escape_code:
65+
return f"{escape_code}{msg}{ANSI_RESET}"
66+
return msg
67+
5868

5969
ColorMappingDict = Dict[str, MessageStyle]
6070

@@ -90,14 +100,7 @@ def _get_ansi_code(self) -> str:
90100

91101
def colorize_ansi(msg: str, msg_style: MessageStyle) -> str:
92102
"""Colorize message by wrapping it with ANSI escape codes."""
93-
if msg_style.color is None and len(msg_style.style) == 0:
94-
# If both color and style are not defined, then leave the text as is.
95-
return msg
96-
escape_code = msg_style._get_ansi_code()
97-
# If invalid (or unknown) color, don't wrap msg with ANSI codes
98-
if escape_code:
99-
return f"{escape_code}{msg}{ANSI_RESET}"
100-
return msg
103+
return msg_style._colorize_ansi(msg)
101104

102105

103106
def make_header(msg: Message) -> str:

0 commit comments

Comments
 (0)