Skip to content

Commit

Permalink
Merge pull request #194 from squatched/support-empty-list-in-get
Browse files Browse the repository at this point in the history
Support Empty List Path In get
  • Loading branch information
moomoohk authored Jun 11, 2024
2 parents fbdd17a + dc3f5d9 commit 22b6c01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dpath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get(
If more than one leaf matches the glob, ValueError is raised. If the glob is
not found and a default is not provided, KeyError is raised.
"""
if glob == "/":
if isinstance(glob, str) and glob == "/" or len(glob) == 0:
return obj

globlist = _split_path(glob, separator)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_get_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def test_util_get_root():
ret = dpath.get(x, '/')
assert ret == x

ret = dpath.get(x, [])
assert ret == x


def test_get_explicit_single():
ehash = {
Expand Down

0 comments on commit 22b6c01

Please sign in to comment.