From d216b7355cead4df98081ba928932899a4f46f7b Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 7 Oct 2023 17:01:46 -0400 Subject: [PATCH] Make HIDE_* attributes always bool For now, this doesn't change how the correspondng environment variables are interpreted, in terms of truth and falsehood. But it does *convert* them to bool, so that the values of the HIDE_WINDOWS_KNOWN_ERRORS and HIDE_WINDOWS_FREEZE_ERRORS attributes are always bools. It also updates the tests accordingly, to validate this behavior. --- git/util.py | 5 ++--- test/test_util.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/git/util.py b/git/util.py index 4b684db4e..6f8666c81 100644 --- a/git/util.py +++ b/git/util.py @@ -117,7 +117,7 @@ log = logging.getLogger(__name__) -def _read_env_flag(name: str, default: bool) -> Union[bool, str]: +def _read_env_flag(name: str, default: bool) -> bool: try: value = os.environ[name] except KeyError: @@ -128,9 +128,8 @@ def _read_env_flag(name: str, default: bool) -> Union[bool, str]: name, ) - # FIXME: This should always return bool, as that is how it is used. # FIXME: This should treat some values besides "" as expressing falsehood. - return value + return bool(value) #: We need an easy way to see if Appveyor TCs start failing, diff --git a/test/test_util.py b/test/test_util.py index 8b789036e..3eb0a1372 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -435,7 +435,7 @@ def run_parse(value): ) return ast.literal_eval(output) - assert_true_iff_win = self.assertTrue if os.name == "nt" else self.assertFalse + true_iff_win = os.name == "nt" # Same as is_win, but don't depend on that here. truthy_cases = [ ("unset", None), @@ -457,8 +457,8 @@ def run_parse(value): for msg, env_var_value in truthy_cases: with self.subTest(msg, env_var_value=env_var_value): - assert_true_iff_win(run_parse(env_var_value)) + self.assertIs(run_parse(env_var_value), true_iff_win) for msg, env_var_value in falsy_cases: with self.subTest(msg, env_var_value=env_var_value): - self.assertFalse(run_parse(env_var_value)) + self.assertIs(run_parse(env_var_value), False)