Skip to content

Commit

Permalink
fixes #630
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Sep 27, 2024
1 parent b1ba35b commit 01e2071
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fastcore/xtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def _expand_import(node, mod, existing):
# %% ../nbs/03_xtras.ipynb
def dict2obj(d, list_func=L, dict_func=AttrDict):
"Convert (possibly nested) dicts (or lists of dicts) to `AttrDict`"
if isinstance(d, (L,list)): return list_func(d).map(dict2obj)
if isinstance(d, (L,list)): return list_func(map(dict2obj, d))
if not isinstance(d, dict): return d
return dict_func(**{k:dict2obj(v) for k,v in d.items()})
return dict_func(**{k:dict2obj(v, list_func=list_func, dict_func=dict_func) for k,v in d.items()})

# %% ../nbs/03_xtras.ipynb
def obj2dict(d):
Expand Down
6 changes: 3 additions & 3 deletions nbs/03_xtras.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@
{
"data": {
"text/plain": [
"'pip 24.0 from /Users/daniel.roy.greenfeld/.virtualenvs/fastcore/lib/python3.10/site-packages/pip (python 3.10)'"
"'pip 23.3.1 from /Users/jhoward/miniconda3/lib/python3.11/site-packages/pip (python 3.11)'"
]
},
"execution_count": null,
Expand Down Expand Up @@ -948,9 +948,9 @@
"#|export\n",
"def dict2obj(d, list_func=L, dict_func=AttrDict):\n",
" \"Convert (possibly nested) dicts (or lists of dicts) to `AttrDict`\"\n",
" if isinstance(d, (L,list)): return list_func(d).map(dict2obj)\n",
" if isinstance(d, (L,list)): return list_func(map(dict2obj, d))\n",
" if not isinstance(d, dict): return d\n",
" return dict_func(**{k:dict2obj(v) for k,v in d.items()})"
" return dict_func(**{k:dict2obj(v, list_func=list_func, dict_func=dict_func) for k,v in d.items()})"
]
},
{
Expand Down

0 comments on commit 01e2071

Please sign in to comment.