Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Precompute stubbed ANSIColors with no colours
  • Loading branch information
hugovk committed Apr 26, 2024
commit 005e44e2da86dd0dc3334f8f731961cfc248609b
18 changes: 9 additions & 9 deletions Lib/_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ class ANSIColors:
YELLOW = "\x1b[33m"


def get_colors(colorize: bool = False) -> ANSIColors:
if colorize or can_colorize():
return ANSIColors()
NoColors = ANSIColors()

ansi_colors = ANSIColors()
for attr in dir(NoColors):
if not attr.startswith("__"):
setattr(NoColors, attr, "")

# Set color attributes to empty strings
for attr in dir(ansi_colors):
if not attr.startswith("__"):
setattr(ansi_colors, attr, "")

return ansi_colors
def get_colors(colorize: bool = False) -> ANSIColors:
if colorize or can_colorize():
return ANSIColors()
else:
Comment thread
hugovk marked this conversation as resolved.
return NoColors


def can_colorize() -> bool:
Expand Down