diff --git a/benedict/core/keypaths.py b/benedict/core/keypaths.py index 6634cab..ddd9c1e 100644 --- a/benedict/core/keypaths.py +++ b/benedict/core/keypaths.py @@ -13,9 +13,8 @@ def keypaths( indexes: bool = False, sort: bool = True, ) -> list[str]: - if separator is None: - separator = "." - if not type_util.is_string(separator) or len(separator) == 0: + separator = "." if separator is None else separator + if not type_util.is_string(separator) or not separator: 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 ceb7afc..043da78 100644 --- a/tests/core/test_keypaths.py +++ b/tests/core/test_keypaths.py @@ -106,7 +106,11 @@ def test_keypaths_with_invalid_separator(self) -> None: with self.assertRaises(ValueError): _ = _keypaths(i, separator=True) # type: ignore[arg-type] - def test_keypaths_with_none_separator(self) -> None: + def test_keypaths_with_empty_separator(self) -> None: + with self.assertRaises(ValueError): + _ = _keypaths({"a": {"b": 1}}, separator="") + + def test_keypaths_without_separator(self) -> None: i = { "a": 1, "b": {