mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
[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 9546fe2ef2
)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
98c25b8e13
commit
c7f9e7446c
3 changed files with 5 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -44,8 +44,10 @@ class TestColorizeFunction(unittest.TestCase):
|
|||
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)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix FORCE_COLOR and NO_COLOR when empty strings. Patch by Hugo van Kemenade.
|
Loading…
Add table
Add a link
Reference in a new issue