'Pretty print the given object.'

def pretty(self, obj):

    obj_id = id(obj)
    cycle = (obj_id in self.stack)
    self.stack.append(obj_id)
    self.begin_group()
    try:
        obj_class = (_safe_getattr(obj, '__class__', None) or type(obj))
        try:
            printer = self.singleton_pprinters[obj_id]
        except (TypeError, KeyError):
            pass
        else:
            return printer(obj, self, cycle)
        for cls in _get_mro(obj_class):
            if (cls in self.type_pprinters):
                return self.type_pprinters[cls](obj, self, cycle)
            else:
                printer = self._in_deferred_types(cls)
                if (printer is not None):
                    return printer(obj, self, cycle)
                elif ('_repr_pretty_' in cls.__dict__):
                    meth = cls._repr_pretty_
                    if callable(meth):
                        return meth(obj, self, cycle)
        return _default_pprint(obj, self, cycle)
    finally:
        self.end_group()
        self.stack.pop()
