@@ -27,20 +27,23 @@ def __trace_key(dict_key: Any, dict_value: Any, key: Any, path: List[Union[str,
27
27
if dict_key_value == key :
28
28
paths = [path ]
29
29
else :
30
- # branch to iterate over list of keys
30
+ # branch to iterate over list of keys
31
+ # this branch will iterate over keys like {'a':1,'b':2,'c':3}
31
32
if (type (dict_value ) == _ast .Dict and len (dict_value .keys ) > 0 ):
32
33
for i in range (len (dict_value .keys )):
33
34
# find array of paths inside the ith branch
34
35
branch_paths = __trace_key (dict_value .keys [i ], dict_value .values [i ], key , path )
35
36
paths = [* paths , * branch_paths ]
36
37
37
- # branch to iterate over dict of list
38
+ # branch to iterate over dict of list
39
+ # this branch will iterate over keys like {'a':1,'b':2,'c':[{'d':'e']}} but skip if c value is list of other types ['d','e']
38
40
if (type (dict_value ) == _ast .List ):
39
41
for elt in dict_value .elts :
40
- for i in range (len (elt .keys )):
41
- # find array of paths inside the ith branch
42
- branch_paths = __trace_key (elt .keys [i ], elt .values [i ], key , path )
43
- paths = [* paths , * branch_paths ]
42
+ if type (elt ) == _ast .Dict :
43
+ for i in range (len (elt .keys )):
44
+ # find array of paths inside the ith branch
45
+ branch_paths = __trace_key (elt .keys [i ], elt .values [i ], key , path )
46
+ paths = [* paths , * branch_paths ]
44
47
return paths
45
48
46
49
0 commit comments