Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion benedict/core/keypaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/core/test_keypaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down