pprintnot looking for any hooks. Instead pprint.PrettyPrinter, a send pattern is used; A number of methods in the class that are referenced class.__repr__.
You can subclass pprint.PrettyPrinterto teach it a class:
class YourPrettyPrinter(pprint.PrettyPrinter):
_dispatch = pprint.PrettyPrinter.copy()
def _pprint_yourtype(self, object, stream, indent, allowance, context, level):
stream.write('YourType(')
self._format(object.foo, stream, indent, allowance + 1,
context, level)
self._format(object.bar, stream, indent, allowance + 1,
context, level)
stream.write(')')
_dispatch[YourType.__repr__] = _pprint_yourtype
, YourType . , , __repr__!
PrettyPrinter._dispatch; self . , :
from pprint import PrettyPrinter
if isinstance(getattr(PrettyPrinter, '_dispatch'), dict):
def pprint_ExtendedConfigParser(printer, object, stream, indent, allowance, context, level):
PrettyPrinter._dispactch[ExtendedConfigParser.__repr__] = pprint_ExtendedConfigParser
pprint , .
, , _dispatch, , . , , .