Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Lib/_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def can_colorize(*, file=None) -> bool:
return False
if os.environ.get("PYTHON_COLORS") == "1":
return True
if "NO_COLOR" in os.environ:
if os.environ.get("NO_COLOR"):
return False
if not COLORIZE:
return False
if "FORCE_COLOR" in os.environ:
if os.environ.get("FORCE_COLOR"):
return True
if os.environ.get("TERM") == "dumb":
return False
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test__colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def check(env, fallback, expected):
check({'TERM': ''}, fallback, fallback)
check({'FORCE_COLOR': '1'}, fallback, True)
check({'FORCE_COLOR': '0'}, fallback, True)
check({'FORCE_COLOR': ''}, fallback, fallback)
check({'NO_COLOR': '1'}, fallback, False)
check({'NO_COLOR': '0'}, fallback, False)
check({'NO_COLOR': ''}, fallback, fallback)

check({'TERM': 'dumb', 'FORCE_COLOR': '1'}, False, True)
check({'FORCE_COLOR': '1', 'NO_COLOR': '1'}, True, False)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix FORCE_COLOR and NO_COLOR when empty strings. Patch by Hugo van Kemenade.
Loading