def _format(self, obj, descend=True):
        """Return a string representation of a single object."""
        if inspect.isframe(obj):
            filename, lineno, func, context, index = inspect.getframeinfo(obj)
            return "<frame of function '%s'>" % func

        if not descend:
            return self.peek(repr(obj))

        if isinstance(obj, dict):
            return (
                '{'
                + ', '.join(
                    [
                        '%s: %s'
                        % (
                            self._format(k, descend=False),
                            self._format(v, descend=False),
                        )
                        for k, v in obj.items()
                    ],
                )
                + '}'
            )
        elif isinstance(obj, list):
            return (
                '['
                + ', '.join(
                    [self._format(item, descend=False) for item in obj],
                )
                + ']'
            )
        elif isinstance(obj, tuple):
            return (
                '('
                + ', '.join(
                    [self._format(item, descend=False) for item in obj],
                )
                + ')'
            )

        r = self.peek(repr(obj))
        if isinstance(obj, (str, int, float)):
            return r
        return '%s: %s' % (type(obj), r)
Return a string representation of a single object.
cherrypy/lib/gctools.py