diff --git a/benedict/core/keypaths.py b/benedict/core/keypaths.py index ca4c9dea..9ba6151f 100644 --- a/benedict/core/keypaths.py +++ b/benedict/core/keypaths.py @@ -13,9 +13,11 @@ def keypaths( indexes: bool = False, sort: bool = True, ) -> list[str]: - separator = separator or "." + separator = "." if separator is None else separator if not type_util.is_string(separator): raise ValueError("separator argument must be a (non-empty) string.") + if 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] if sort: diff --git a/tests/core/test_keypaths.py b/tests/core/test_keypaths.py index 5d4faa6f..62834ad1 100644 --- a/tests/core/test_keypaths.py +++ b/tests/core/test_keypaths.py @@ -106,6 +106,10 @@ def test_keypaths_with_invalid_separator(self) -> None: with self.assertRaises(ValueError): _ = _keypaths(i, separator=True) # type: ignore[arg-type] + 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,