MCPcopy Create free account
hub / github.com/ipython/ipython / _set_pprinter_factory

Function _set_pprinter_factory

IPython/lib/pretty.py:563–587  ·  view source on GitHub ↗

Factory that returns a pprint function useful for sets and frozensets.

(start, end)

Source from the content-addressed store, hash-verified

561
562
563def _set_pprinter_factory(start, end):
564 """
565 Factory that returns a pprint function useful for sets and frozensets.
566 """
567 def inner(obj, p, cycle):
568 if cycle:
569 return p.text(start + '...' + end)
570 if len(obj) == 0:
571 # Special case.
572 p.text(type(obj).__name__ + '()')
573 else:
574 step = len(start)
575 p.begin_group(step, start)
576 # Like dictionary keys, we will try to sort the items if there aren't too many
577 if not (p.max_seq_length and len(obj) >= p.max_seq_length):
578 items = _sorted_for_pprint(obj)
579 else:
580 items = obj
581 for idx, x in p._enumerate(items):
582 if idx:
583 p.text(',')
584 p.breakable()
585 p.pretty(x)
586 p.end_group(step, end)
587 return inner
588
589
590def _dict_pprinter_factory(start, end):

Callers 1

pretty.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected