Skip to content

Commit 333896b

Browse files
committed
Treat false-seeming HIDE_* env var values as false
This changes how HIDE_WINDOWS_KNOWN_ERRORS and HIDE_WINDOWS_FREEZE_ERRORS environment variables, if present, are interpreted, so that values that strongly seem intuitivley to represent falsehood now do. Before, only the empty string was treated as false. Now: - "0", "false", "no", and their case variants, as well as the empty string, are treated as false. - The presence of leading and trailing whitespace in the value now longer changes the truth value it represents. For example, all-whitespace (e.g., a space) is treated as false. - Values other than the above false values, and the recognized true values "1", "true", "yes", and their variants, are still treated as true, but issue a warning about how they are unrecognied.
1 parent eb51277 commit 333896b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Diff for: git/util.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ def _read_env_flag(name: str, default: bool) -> bool:
121121
name,
122122
)
123123

124-
# FIXME: This should treat some values besides "" as expressing falsehood.
125-
return bool(value)
124+
adjusted_value = value.strip().lower()
125+
126+
if adjusted_value in {"", "0", "false", "no"}:
127+
return False
128+
if adjusted_value in {"1", "true", "yes"}:
129+
return True
130+
log.warning("%s has unrecognized value %r, treating as %r.", name, value, default)
131+
return default
126132

127133

128134
#: We need an easy way to see if Appveyor TCs start failing,

Diff for: test/test_util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,15 @@ def run_parse(value):
529529
("true-seeming", "True"),
530530
("true-seeming", "yes"),
531531
("true-seeming", "YES"),
532+
]
533+
falsy_cases = [
534+
("empty", ""),
535+
("whitespace", " "),
532536
("false-seeming", "0"),
533537
("false-seeming", "false"),
534538
("false-seeming", "False"),
535539
("false-seeming", "no"),
536540
("false-seeming", "NO"),
537-
("whitespace", " "),
538-
]
539-
falsy_cases = [
540-
("empty", ""),
541541
]
542542

543543
for msg, env_var_value in truthy_cases:

0 commit comments

Comments
 (0)