diff --git a/IPython/core/formatters.py b/IPython/core/formatters.py index 5afea82..cad2520 100644 --- a/IPython/core/formatters.py +++ b/IPython/core/formatters.py @@ -149,7 +149,7 @@ class DisplayFormatter(Configurable): # object handled itself, don't proceed return {}, {} - format_dict, md_dict = self.mimebundle_formatter(obj) + format_dict, md_dict = self.mimebundle_formatter(obj, include=include, exclude=exclude) if format_dict or md_dict: if include: @@ -943,6 +943,35 @@ class MimeBundleFormatter(BaseFormatter): return r, {} return r + @catch_format_error + def __call__(self, obj, include=None, exclude=None): + """Compute the format for an object. + + Identical to parent's method but we pass extra parameters to the method. + + Unlike other _repr_*_ `_repr_mimebundle_` should allow extra kwargs, in + particular `include` and `exclude`. + """ + if self.enabled: + # lookup registered printer + try: + printer = self.lookup(obj) + except KeyError: + pass + else: + return printer(obj) + # Finally look for special method names + method = get_real_method(obj, self.print_method) + + if method is not None: + d = {} + d['include'] = include + d['exclude'] = include + return method(**d) + return None + else: + return None + FormatterABC.register(BaseFormatter) FormatterABC.register(PlainTextFormatter) diff --git a/IPython/core/tests/test_formatters.py b/IPython/core/tests/test_formatters.py index 84156ad..75e69a4 100644 --- a/IPython/core/tests/test_formatters.py +++ b/IPython/core/tests/test_formatters.py @@ -440,7 +440,7 @@ def test_json_as_string_deprecated(): def test_repr_mime(): class HasReprMime(object): - def _repr_mimebundle_(self): + def _repr_mimebundle_(self, include=None, exclude=None): return { 'application/json+test.v2': { 'x': 'y' @@ -477,7 +477,7 @@ def test_repr_mime(): def test_repr_mime_meta(): class HasReprMimeMeta(object): - def _repr_mimebundle_(self): + def _repr_mimebundle_(self, include=None, exclude=None): data = { 'image/png': 'base64-image-data', }