8000 gh-117225: Move colorize functionality to own internal module by hugovk · Pull Request #118283 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117225: Move colorize functionality to own internal module #118283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 1, 2024
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 lin A2EF e 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:
return NoColors


def can_colorize() -> bool:
Expand Down
Loading
0