From be7114821f3aece0b24962c86638e715fea6fc04 2016-06-08 09:53:04 From: Min RK Date: 2016-06-08 09:53:04 Subject: [PATCH] InteractiveShell.object_inspect_text must return text That's the whole point of it. Adds object_inspect_mime for returning the mimebundle of formatted outputs, which `_get_info` now returns. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index aca1a54..4a55669 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1579,6 +1579,14 @@ class InteractiveShell(SingletonConfigurable): def object_inspect_text(self, oname, detail_level=0): """Get object info as formatted text""" + return self.object_inspect_mime(oname, detail_level)['text/plain'] + + def object_inspect_mime(self, oname, detail_level=0): + """Get object info as a mimebundle of formatted representations. + + A mimebundle is a dictionary, keyed by mime-type. + It must always have the key `'text/plain'`. + """ with self.builtin_trap: info = self._object_find(oname) if info.found: diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 3a38c84..db22c15 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -514,6 +514,12 @@ class InteractiveShellTestCase(unittest.TestCase): else: self.assertEqual(msg, 'IPython.core.tests.test_interactiveshell.DerivedInterrupt: foo\n') + def test_inspect_text(self): + ip.run_cell('a = 5') + text = ip.object_inspect_text('a') + self.assertIsInstance(text, unicode_type) + + class TestSafeExecfileNonAsciiPath(unittest.TestCase): @onlyif_unicode_paths