Show More
@@ -119,6 +119,21 b' else:' | |||
|
119 | 119 | cast_unicode(text, encoding=get_stream_enc(sys.stdout))) |
|
120 | 120 | |
|
121 | 121 | |
|
122 | def _sorted_for_pprint(items): | |
|
123 | """ | |
|
124 | Sort the given items for pretty printing. Since some predictable | |
|
125 | sorting is better than no sorting at all, we sort on the string | |
|
126 | representation if normal sorting fails. | |
|
127 | """ | |
|
128 | items = list(items) | |
|
129 | try: | |
|
130 | return sorted(items) | |
|
131 | except Exception: | |
|
132 | try: | |
|
133 | return sorted(items, key=str) | |
|
134 | except Exception: | |
|
135 | return items | |
|
136 | ||
|
122 | 137 | def pretty(obj, verbose=False, max_width=79, newline='\n', max_seq_length=MAX_SEQ_LENGTH): |
|
123 | 138 | """ |
|
124 | 139 | Pretty print the object's representation. |
@@ -576,13 +591,10 b' def _set_pprinter_factory(start, end, basetype):' | |||
|
576 | 591 | step = len(start) |
|
577 | 592 | p.begin_group(step, start) |
|
578 | 593 | # Like dictionary keys, we will try to sort the items if there aren't too many |
|
579 | items = obj | |
|
580 | 594 | if not (p.max_seq_length and len(obj) >= p.max_seq_length): |
|
581 | try: | |
|
582 | items = sorted(obj) | |
|
583 |
|
|
|
584 | # Sometimes the items don't sort. | |
|
585 | pass | |
|
595 | items = _sorted_for_pprint(obj) | |
|
596 | else: | |
|
597 | items = obj | |
|
586 | 598 | for idx, x in p._enumerate(items): |
|
587 | 599 | if idx: |
|
588 | 600 | p.text(',') |
@@ -610,11 +622,7 b' def _dict_pprinter_factory(start, end, basetype=None):' | |||
|
610 | 622 | keys = obj.keys() |
|
611 | 623 | # if dict isn't large enough to be truncated, sort keys before displaying |
|
612 | 624 | if not (p.max_seq_length and len(obj) >= p.max_seq_length): |
|
613 | try: | |
|
614 | keys = sorted(keys) | |
|
615 | except Exception: | |
|
616 | # Sometimes the keys don't sort. | |
|
617 | pass | |
|
625 | keys = _sorted_for_pprint(keys) | |
|
618 | 626 | for idx, key in p._enumerate(keys): |
|
619 | 627 | if idx: |
|
620 | 628 | p.text(',') |
General Comments 0
You need to be logged in to leave comments.
Login now