From 19888222dcbb4d67f53407d1c751f36dacc4a3ce Mon Sep 17 00:00:00 2001 From: Aviv Shahar Date: Sun, 13 Dec 2020 12:55:12 +0200 Subject: [PATCH] ipython repr of Bunch to support un-sortable objects --- easypy/humanize.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/easypy/humanize.py b/easypy/humanize.py index c7ea279..d7f6be3 100644 --- a/easypy/humanize.py +++ b/easypy/humanize.py @@ -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 = ' ▏▎▍▌▋▊▉██'