diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py index d54bcd4..09f845a 100644 --- a/IPython/lib/pretty.py +++ b/IPython/lib/pretty.py @@ -122,6 +122,7 @@ else: __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter', 'for_type', 'for_type_by_name'] +SEQ_LENGTH_LIMIT = 1000 _re_pattern_type = type(re.compile('')) @@ -599,6 +600,12 @@ def _seq_pprinter_factory(start, end, basetype): step = len(start) p.begin_group(step, start) for idx, x in enumerate(obj): + if idx >= SEQ_LENGTH_LIMIT: + p.text(',') + p.breakable() + p.text('...') + p.end_group(step, end) + return if idx: p.text(',') p.breakable() @@ -636,6 +643,12 @@ def _set_pprinter_factory(start, end, basetype): # Sometimes the items don't sort. pass for idx, x in enumerate(items): + if idx >= SEQ_LENGTH_LIMIT: + p.text(',') + p.breakable() + p.text('...') + p.end_group(step, end) + return if idx: p.text(',') p.breakable() @@ -665,6 +678,12 @@ def _dict_pprinter_factory(start, end, basetype=None): # Sometimes the keys don't sort. pass for idx, key in enumerate(keys): + if idx >= SEQ_LENGTH_LIMIT: + p.text(',') + p.breakable() + p.text('...') + p.end_group(1, end) + return if idx: p.text(',') p.breakable() diff --git a/IPython/lib/tests/test_pretty.py b/IPython/lib/tests/test_pretty.py index 009512d..767f441 100644 --- a/IPython/lib/tests/test_pretty.py +++ b/IPython/lib/tests/test_pretty.py @@ -196,4 +196,29 @@ def test_super_repr(): sb = SB() output = pretty.pretty(super(SA, sb)) nt.assert_in("SA", output) - \ No newline at end of file + + +def test_long_list(): + lis = list(range(10000)) + p = pretty.pretty(lis) + last2 = p.rsplit('\n', 2)[-2:] + nt.assert_equal(last2, [' 999,', ' ...]']) + +def test_long_set(): + s = set(range(10000)) + p = pretty.pretty(s) + last2 = p.rsplit('\n', 2)[-2:] + nt.assert_equal(last2, [' 999,', ' ...}']) + +def test_long_tuple(): + tup = tuple(range(10000)) + p = pretty.pretty(tup) + last2 = p.rsplit('\n', 2)[-2:] + nt.assert_equal(last2, [' 999,', ' ...)']) + +def test_long_dict(): + d = { n:n for n in range(10000) } + p = pretty.pretty(d) + last2 = p.rsplit('\n', 2)[-2:] + nt.assert_equal(last2, [' 999: 999,', ' ...}']) +