def _repr_pretty_(self, p, cycle):
class_name = type(self).__name__<EOL>if cycle:<EOL><INDENT>p.text('<STR_LIT>'.format(<EOL>cls=class_name,<EOL>))<EOL><DEDENT>else:<EOL><INDENT>with p.group(<EOL>len(class_name) + <NUM_LIT:1>,<EOL>'<STR_LIT>'.format(cls=class_name),<EOL>'<STR_LIT:)>',<EOL>):<EOL><INDENT>prepared = self.as_json_compatible()<EOL>if isinstance(prepared, Mapping):<EOL><INDENT>p.text('<STR_LIT>')<EOL><DEDENT>elif isinstance(prepared, Iterable):<EOL><INDENT>p.text('<STR_LIT:*>')<EOL><DEDENT>p.pretty(prepared)<EOL><DEDENT><DEDENT>
Makes JSON-serializable objects play nice with IPython's default
pretty-printer.

Sadly, :py:func:`pprint.pprint` does not have a similar
mechanism.

References:

- http://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.pretty.html
- :py:meth:`IPython.lib.pretty.RepresentationPrinter.pretty`
- :py:func:`pprint._safe_repr`