Skip to content

Commit c7f9e74

Browse files
[3.13] gh-129061: Fix FORCE_COLOR and NO_COLOR when empty strings (GH-129140) (#129360)
gh-129061: Fix `FORCE_COLOR` and `NO_COLOR` when empty strings (GH-129140) (cherry picked from commit 9546fe2) Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 98c25b8 commit c7f9e74

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Lib/_colorize.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def can_colorize(*, file=None) -> bool:
4040
return False
4141
if os.environ.get("PYTHON_COLORS") == "1":
4242
return True
43-
if "NO_COLOR" in os.environ:
43+
if os.environ.get("NO_COLOR"):
4444
return False
4545
if not COLORIZE:
4646
return False
47-
if "FORCE_COLOR" in os.environ:
47+
if os.environ.get("FORCE_COLOR"):
4848
return True
4949
if os.environ.get("TERM") == "dumb":
5050
return False

Lib/test/test__colorize.py

+2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def check(env, fallback, expected):
4444
check({'TERM': ''}, fallback, fallback)
4545
check({'FORCE_COLOR': '1'}, fallback, True)
4646
check({'FORCE_COLOR': '0'}, fallback, True)
47+
check({'FORCE_COLOR': ''}, fallback, fallback)
4748
check({'NO_COLOR': '1'}, fallback, False)
4849
check({'NO_COLOR': '0'}, fallback, False)
50+
check({'NO_COLOR': ''}, fallback, fallback)
4951

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

0 commit comments

Comments
 (0)