Skip to content

Commit

Permalink
ipython repr of Bunch to support un-sortable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
avivshahar committed Dec 13, 2020
1 parent 3a6e55f commit 1988822
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion easypy/humanize.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,13 @@ def ipython_fields_repr(name, field_items, p, cycle):

def ipython_mapping_repr(mapping, p, cycle):
"""Used by IPython. add to any mapping class as '_repr_pretty_'"""
ipython_fields_repr(mapping.__class__.__name__, sorted(mapping.items()), p, cycle)
try:
mapping_items = sorted(mapping.items())
except TypeError:
# some objcets do not support sorting
mapping_items = list(mapping.items())

ipython_fields_repr(mapping.__class__.__name__, mapping_items, p, cycle)


BAR_SEQUENCE = ' ▏▎▍▌▋▊▉██'
Expand Down

0 comments on commit 1988822

Please sign in to comment.