MCPcopy Index your code
hub / github.com/ipython/ipython / PlainTextFormatter

Class PlainTextFormatter

IPython/core/formatters.py:631–772  ·  view source on GitHub ↗

The default pretty-printer. This uses :mod:`IPython.lib.pretty` to compute the format data of the object. If the object cannot be pretty printed, :func:`repr` is used. See the documentation of :mod:`IPython.lib.pretty` for details on how to write pretty printers. Here is a simple e

Source from the content-addressed store, hash-verified

629
630
631class PlainTextFormatter(BaseFormatter):
632 """The default pretty-printer.
633
634 This uses :mod:`IPython.lib.pretty` to compute the format data of
635 the object. If the object cannot be pretty printed, :func:`repr` is used.
636 See the documentation of :mod:`IPython.lib.pretty` for details on
637 how to write pretty printers. Here is a simple example::
638
639 def dtype_pprinter(obj, p, cycle):
640 if cycle:
641 return p.text('dtype(...)')
642 if hasattr(obj, 'fields'):
643 if obj.fields is None:
644 p.text(repr(obj))
645 else:
646 p.begin_group(7, 'dtype([')
647 for i, field in enumerate(obj.descr):
648 if i > 0:
649 p.text(',')
650 p.breakable()
651 p.pretty(field)
652 p.end_group(7, '])')
653 """
654
655 # The format type of data returned.
656 format_type = Unicode('text/plain')
657
658 # This subclass ignores this attribute as it always need to return
659 # something.
660 enabled = Bool(True).tag(config=False)
661
662 max_seq_length = Integer(pretty.MAX_SEQ_LENGTH,
663 help="""Truncate large collections (lists, dicts, tuples, sets) to this size.
664
665 Set to 0 to disable truncation.
666 """,
667 ).tag(config=True)
668
669 # Look for a _repr_pretty_ methods to use for pretty printing.
670 print_method = ObjectName('_repr_pretty_')
671
672 # Whether to pretty-print or not.
673 pprint = Bool(True).tag(config=True)
674
675 # Whether to be verbose or not.
676 verbose = Bool(False).tag(config=True)
677
678 # The maximum width.
679 max_width = Integer(79).tag(config=True)
680
681 # The newline character.
682 newline = Unicode('\n').tag(config=True)
683
684 # format-string for pprinting floats
685 float_format = Unicode('%r')
686 # setter for float precision, either int or direct format-string
687 float_precision = CUnicode('').tag(config=True)
688

Callers 15

test_prettyFunction · 0.90
test_deferredFunction · 0.90
test_precisionFunction · 0.90
test_bad_precisionFunction · 0.90
test_for_typeFunction · 0.90
test_for_type_stringFunction · 0.90
test_for_type_by_nameFunction · 0.90
test_lookupFunction · 0.90
test_lookup_stringFunction · 0.90
test_lookup_by_typeFunction · 0.90
test_in_formatterFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_prettyFunction · 0.72
test_deferredFunction · 0.72
test_precisionFunction · 0.72
test_bad_precisionFunction · 0.72
test_for_typeFunction · 0.72
test_for_type_stringFunction · 0.72
test_for_type_by_nameFunction · 0.72
test_lookupFunction · 0.72
test_lookup_stringFunction · 0.72
test_lookup_by_typeFunction · 0.72
test_in_formatterFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…