diff --git a/benedict/core/keypaths.py b/benedict/core/keypaths.py index ca4c9dea..6634cab8 100644 --- a/benedict/core/keypaths.py +++ b/benedict/core/keypaths.py @@ -13,8 +13,9 @@ def keypaths( indexes: bool = False, sort: bool = True, ) -> list[str]: - separator = separator or "." - if not type_util.is_string(separator): + if separator is None: + separator = "." + if not type_util.is_string(separator) or len(separator) == 0: raise ValueError("separator argument must be a (non-empty) string.") kls = keylists(d, indexes=indexes) kps = [separator.join([f"{key}" for key in kl]) for kl in kls] diff --git a/tests/core/test_keypaths.py b/tests/core/test_keypaths.py index 5d4faa6f..ceb7afc7 100644 --- a/tests/core/test_keypaths.py +++ b/tests/core/test_keypaths.py @@ -106,7 +106,7 @@ def test_keypaths_with_invalid_separator(self) -> None: with self.assertRaises(ValueError): _ = _keypaths(i, separator=True) # type: ignore[arg-type] - def test_keypaths_without_separator(self) -> None: + def test_keypaths_with_none_separator(self) -> None: i = { "a": 1, "b": { @@ -120,9 +120,7 @@ def test_keypaths_without_separator(self) -> None: }, }, } - # with self.assertRaises(ValueError): - # o = _keypaths(i, separator=None) - o = _keypaths(i) + o = _keypaths(i, separator=None) r = [ "a", "b",