##// END OF EJS Templates
ENH: Make the set pretty-printer sort the elements if possible, similar to dict keys.
Robert Kern -
Show More
@@ -554,7 +554,14 b' def _set_pprinter_factory(start, end, basetype):'
554 554 else:
555 555 step = len(start)
556 556 p.begin_group(step, start)
557 for idx, x in enumerate(obj):
557 # Like dictionary keys, we will try to sort the items.
558 items = list(obj)
559 try:
560 items.sort()
561 except Exception:
562 # Sometimes the items don't sort.
563 pass
564 for idx, x in enumerate(items):
558 565 if idx:
559 566 p.text(',')
560 567 p.breakable()
@@ -90,9 +90,9 b' def test_sets():'
90 90 Test that set and frozenset use Python 3 formatting.
91 91 """
92 92 objects = [set(), frozenset(), set([1]), frozenset([1]), set([1,2]),
93 frozenset([1,2])]
93 frozenset([1, 2]), set([-1, -2, -3])]
94 94 expected = ['set()', 'frozenset()', '{1}', 'frozenset({1})', '{1, 2}',
95 'frozenset({1, 2})']
95 'frozenset({1, 2})', '{-3, -2, -1}']
96 96 for obj, expected_output in zip(objects, expected):
97 97 got_output = pretty.pretty(obj)
98 98 yield nt.assert_equal, got_output, expected_output
General Comments 0
You need to be logged in to leave comments. Login now