Skip to content

Commit a6fc9b3

Browse files
committed
less indentation the better
1 parent f75c45d commit a6fc9b3

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/sagemaker/jumpstart/curated_hub/parser_utils.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,24 @@ def walk_and_apply_json(json_obj: Dict[Any, Any], apply) -> Dict[Any, Any]:
3333
"""Recursively walks a json object and applies a given function to the keys."""
3434

3535
def _walk_and_apply_json(json_obj, new):
36-
if isinstance(json_obj, dict):
37-
if isinstance(new, dict):
38-
for key, value in json_obj.items():
39-
new_key = apply(key)
40-
if isinstance(value, dict):
41-
new[new_key] = {}
42-
_walk_and_apply_json(value, new=new[new_key])
43-
elif isinstance(value, list):
44-
new[new_key] = []
45-
for item in value:
46-
_walk_and_apply_json(item, new=new[new_key])
47-
else:
48-
new[new_key] = value
49-
elif isinstance(new, list):
50-
new.append(_walk_and_apply_json(json_obj, new={}))
51-
elif isinstance(json_obj, list):
52-
if isinstance(new, dict):
53-
new.update(json_obj)
54-
elif isinstance(new, list):
55-
new.append(json_obj)
36+
if isinstance(json_obj, dict) and isinstance(new, dict):
37+
for key, value in json_obj.items():
38+
new_key = apply(key)
39+
if isinstance(value, dict):
40+
new[new_key] = {}
41+
_walk_and_apply_json(value, new=new[new_key])
42+
elif isinstance(value, list):
43+
new[new_key] = []
44+
for item in value:
45+
_walk_and_apply_json(item, new=new[new_key])
46+
else:
47+
new[new_key] = value
48+
elif isinstance(json_obj, dict) and isinstance(new, list):
49+
new.append(_walk_and_apply_json(json_obj, new={}))
50+
elif isinstance(json_obj, list) and isinstance(new, dict):
51+
new.update(json_obj)
52+
elif isinstance(json_obj, list) and isinstance(new, list):
53+
new.append(json_obj)
5654
return new
5755

5856
return _walk_and_apply_json(json_obj, new={})

0 commit comments

Comments
 (0)