Skip to content
Merged
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
5 changes: 2 additions & 3 deletions benedict/core/keypaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 5 additions & 1 deletion tests/core/test_keypaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Loading