From 4802b3efda6277fbe3fb6ce1947fd70adebb6ce6 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Fri, 9 Dec 2022 13:23:38 -0600 Subject: [PATCH 1/6] Use !r and repr to make exception messages clearer. --- src/tox/config/loader/str_convert.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py index dd518e5e3..8f3368156 100644 --- a/src/tox/config/loader/str_convert.py +++ b/src/tox/config/loader/str_convert.py @@ -81,13 +81,14 @@ def to_env_list(value: str) -> EnvList: @staticmethod def to_bool(value: str) -> bool: - norm = value.strip().lower() + norm = str(value).strip().lower() if norm in StrConvert.TRUTHFUL_VALUES: return True elif norm in StrConvert.FALSE_VALUES: return False else: - raise TypeError(f"value {value} cannot be transformed to bool, valid: {', '.join(StrConvert.VALID_BOOL)}") + raise TypeError(f"value {value!r} cannot be transformed to bool," + f" valid values: {', '.join(repr(vb) for vb in StrConvert.VALID_BOOL)}") __all__ = ("StrConvert",) From 3bbb14563530123ffcad678e98c748cc650b947c Mon Sep 17 00:00:00 2001 From: ptmcg Date: Fri, 9 Dec 2022 13:41:22 -0600 Subject: [PATCH 2/6] Use !r and repr to make exception messages clearer. Add changelog file --- docs/changelog/2665.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changelog/2665.bugfix.rst diff --git a/docs/changelog/2665.bugfix.rst b/docs/changelog/2665.bugfix.rst new file mode 100644 index 000000000..0df0766b2 --- /dev/null +++ b/docs/changelog/2665.bugfix.rst @@ -0,0 +1 @@ +Use ``!r`` and ``repr()`` to better display erroneous values in exception from ``StrConverter.to_bool()`` - by :user:`ptmcg`. \ No newline at end of file From ea0a89351150ea1115e0f9db27d648786042abc5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 19:43:22 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/changelog/2665.bugfix.rst | 2 +- src/tox/config/loader/str_convert.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/changelog/2665.bugfix.rst b/docs/changelog/2665.bugfix.rst index 0df0766b2..a4be5e9df 100644 --- a/docs/changelog/2665.bugfix.rst +++ b/docs/changelog/2665.bugfix.rst @@ -1 +1 @@ -Use ``!r`` and ``repr()`` to better display erroneous values in exception from ``StrConverter.to_bool()`` - by :user:`ptmcg`. \ No newline at end of file +Use ``!r`` and ``repr()`` to better display erroneous values in exception from ``StrConverter.to_bool()`` - by :user:`ptmcg`. diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py index 8f3368156..4cf6bea4e 100644 --- a/src/tox/config/loader/str_convert.py +++ b/src/tox/config/loader/str_convert.py @@ -87,8 +87,10 @@ def to_bool(value: str) -> bool: elif norm in StrConvert.FALSE_VALUES: return False else: - raise TypeError(f"value {value!r} cannot be transformed to bool," - f" valid values: {', '.join(repr(vb) for vb in StrConvert.VALID_BOOL)}") + raise TypeError( + f"value {value!r} cannot be transformed to bool," + f" valid values: {', '.join(repr(vb) for vb in StrConvert.VALID_BOOL)}", + ) __all__ = ("StrConvert",) From 451d304603f509782ba05626712dbe37dc74a91c Mon Sep 17 00:00:00 2001 From: ptmcg Date: Fri, 9 Dec 2022 14:31:32 -0600 Subject: [PATCH 4/6] Reverted repr() on VALID_BOOL list; updated relevant test --- src/tox/config/loader/str_convert.py | 3 +-- tests/config/test_sets.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py index 4cf6bea4e..9fabf33f8 100644 --- a/src/tox/config/loader/str_convert.py +++ b/src/tox/config/loader/str_convert.py @@ -88,8 +88,7 @@ def to_bool(value: str) -> bool: return False else: raise TypeError( - f"value {value!r} cannot be transformed to bool," - f" valid values: {', '.join(repr(vb) for vb in StrConvert.VALID_BOOL)}", + f"value {value!r} cannot be transformed to bool, valid values: {', '.join(StrConvert.VALID_BOOL)}" ) diff --git a/tests/config/test_sets.py b/tests/config/test_sets.py index ca5778754..0faa68acd 100644 --- a/tests/config/test_sets.py +++ b/tests/config/test_sets.py @@ -89,7 +89,7 @@ def test_config_bad_bool(conf_builder: ConfBuilder) -> None: config_set.add_config(keys="bad_bool", of_type=bool, default=False, desc="bad_bool") with pytest.raises(TypeError) as context: assert config_set["bad_bool"] - error = "value whatever cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes" + error = "value 'whatever' cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes" assert str(context.value) == error From a796ecede20b5d1b3655391337ccf262dc63f5a9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 20:34:47 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/tox/config/loader/str_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py index 9fabf33f8..cdaae48b8 100644 --- a/src/tox/config/loader/str_convert.py +++ b/src/tox/config/loader/str_convert.py @@ -88,7 +88,7 @@ def to_bool(value: str) -> bool: return False else: raise TypeError( - f"value {value!r} cannot be transformed to bool, valid values: {', '.join(StrConvert.VALID_BOOL)}" + f"value {value!r} cannot be transformed to bool, valid values: {', '.join(StrConvert.VALID_BOOL)}", ) From e3d8c2f8b4db5de6fdc0b6b49e2f7af0707c82b8 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Fri, 9 Dec 2022 14:47:19 -0600 Subject: [PATCH 6/6] Fixed test-breaking typo --- src/tox/config/loader/str_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py index cdaae48b8..e31c034f0 100644 --- a/src/tox/config/loader/str_convert.py +++ b/src/tox/config/loader/str_convert.py @@ -88,7 +88,7 @@ def to_bool(value: str) -> bool: return False else: raise TypeError( - f"value {value!r} cannot be transformed to bool, valid values: {', '.join(StrConvert.VALID_BOOL)}", + f"value {value!r} cannot be transformed to bool, valid: {', '.join(StrConvert.VALID_BOOL)}", )