Skip to content

Commit 1988822

Browse files
committed
ipython repr of Bunch to support un-sortable objects
1 parent 3a6e55f commit 1988822

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

easypy/humanize.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,13 @@ def ipython_fields_repr(name, field_items, p, cycle):
614614

615615
def ipython_mapping_repr(mapping, p, cycle):
616616
"""Used by IPython. add to any mapping class as '_repr_pretty_'"""
617-
ipython_fields_repr(mapping.__class__.__name__, sorted(mapping.items()), p, cycle)
617+
try:
618+
mapping_items = sorted(mapping.items())
619+
except TypeError:
620+
# some objcets do not support sorting
621+
mapping_items = list(mapping.items())
622+
623+
ipython_fields_repr(mapping.__class__.__name__, mapping_items, p, cycle)
618624

619625

620626
BAR_SEQUENCE = ' ▏▎▍▌▋▊▉██'

0 commit comments

Comments
 (0)