Skip to content

Commit

Permalink
Merge pull request #663 from ssslakter/main
Browse files Browse the repository at this point in the history
change `asdict` order
  • Loading branch information
jph00 authored Jan 15, 2025
2 parents 9a80a39 + d6bd1c3 commit 62e622c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fastcore/xtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ def flexiclass(
def asdict(o)->dict:
"Convert `o` to a `dict`, supporting dataclasses, namedtuples, iterables, and `__dict__` attrs."
if isinstance(o, dict): return o
if is_dataclass(o): r = dataclasses.asdict(o)
elif hasattr(o, '_asdict'): r = o._asdict()
if hasattr(o, '_asdict'): r = o._asdict()
elif is_dataclass(o): r = dataclasses.asdict(o)
elif hasattr(o, '__iter__'):
try: r = dict(o)
except TypeError: pass
Expand Down
4 changes: 2 additions & 2 deletions nbs/03_xtras.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3032,8 +3032,8 @@
"def asdict(o)->dict:\n",
" \"Convert `o` to a `dict`, supporting dataclasses, namedtuples, iterables, and `__dict__` attrs.\"\n",
" if isinstance(o, dict): return o\n",
" if is_dataclass(o): r = dataclasses.asdict(o)\n",
" elif hasattr(o, '_asdict'): r = o._asdict()\n",
" if hasattr(o, '_asdict'): r = o._asdict()\n",
" elif is_dataclass(o): r = dataclasses.asdict(o)\n",
" elif hasattr(o, '__iter__'):\n",
" try: r = dict(o)\n",
" except TypeError: pass\n",
Expand Down

0 comments on commit 62e622c

Please sign in to comment.