Skip to content

Commit a673d24

Browse files
committed
Support Empty List Path In get
Solves Issue dpath-maintainers#193. Currently, dpath.get() works with a path of '/' by returning the value of the object passed in. This behavior is not reflected with an empty list. Now, passing an empty list to dpath.get() will behave the same way (returning the root object value).
1 parent e0d412f commit a673d24

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

dpath/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get(
167167
If more than one leaf matches the glob, ValueError is raised. If the glob is
168168
not found and a default is not provided, KeyError is raised.
169169
"""
170-
if glob == "/":
170+
if glob == "/" or (type(glob) is not str and len(glob) == 0):
171171
return obj
172172

173173
globlist = _split_path(glob, separator)

tests/test_get_values.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def test_util_get_root():
1717
ret = dpath.get(x, '/')
1818
assert ret == x
1919

20+
ret = dpath.get(x, [])
21+
assert ret == x
22+
2023

2124
def test_get_explicit_single():
2225
ehash = {

0 commit comments

Comments
 (0)