From 0924c6972e837161bc82a687c4117d69c9481e37 2010-10-29 23:20:24 From: Robert Kern Date: 2010-10-29 23:20:24 Subject: [PATCH] ENH: Use text/plain for the format string of the DefaultFormatter. BUG: Return None if repr() fails. --- diff --git a/IPython/core/formatters.py b/IPython/core/formatters.py index 55d2ebd..2bf9708 100644 --- a/IPython/core/formatters.py +++ b/IPython/core/formatters.py @@ -53,7 +53,8 @@ class DefaultFormatter(Configurable): id = Str('default') # The kind of data returned. - format = Str('text') + # This is often, but not always a MIME type. + format = Str('text/plain') # Whether to pretty-print or not. pprint = Bool(True, config=True) @@ -143,12 +144,17 @@ class FormatterABC(object): id = 'abstract' # The kind of data returned. - format = 'text' + format = 'text/plain' @abc.abstractmethod def __call__(self, obj): """ Return a JSONable representation of the object. + + If the object cannot be formatted by this formatter, then return None """ - return repr(obj) + try: + return repr(obj) + except TypeError: + return None FormatterABC.register(DefaultFormatter)