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

Function _default_pprint

IPython/lib/pretty.py:503–538  ·  view source on GitHub ↗

The default print function. Used if an object does not provide one and it's none of the builtin objects.

(obj, p, cycle)

Source from the content-addressed store, hash-verified

501
502
503def _default_pprint(obj, p, cycle):
504 """
505 The default print function. Used if an object does not provide one and
506 it's none of the builtin objects.
507 """
508 klass = _safe_getattr(obj, '__class__', None) or type(obj)
509 if _safe_getattr(klass, '__repr__', None) is not object.__repr__:
510 # A user-provided repr. Find newlines and replace them with p.break_()
511 _repr_pprint(obj, p, cycle)
512 return
513 p.begin_group(1, '<')
514 p.pretty(klass)
515 p.text(' at 0x%x' % id(obj))
516 if cycle:
517 p.text(' ...')
518 elif p.verbose:
519 first = True
520 for key in dir(obj):
521 if not key.startswith('_'):
522 try:
523 value = getattr(obj, key)
524 except AttributeError:
525 continue
526 if isinstance(value, types.MethodType):
527 continue
528 if not first:
529 p.text(',')
530 p.breakable()
531 p.text(key)
532 p.text('=')
533 step = len(key) + 1
534 p.indentation += step
535 p.pretty(value)
536 p.indentation -= step
537 first = False
538 p.end_group(1, '>')
539
540
541def _seq_pprinter_factory(start, end):

Callers 1

prettyMethod · 0.85

Calls 7

_safe_getattrFunction · 0.85
_repr_pprintFunction · 0.85
begin_groupMethod · 0.80
prettyMethod · 0.80
breakableMethod · 0.80
end_groupMethod · 0.80
textMethod · 0.45

Tested by

no test coverage detected