diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index b8c7cd2..a880c29 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2078,7 +2078,7 @@ class InteractiveShell(SingletonConfigurable): try: print(val) except UnicodeEncodeError: - print(val.encode('utf-8', 'backslashreplace').decode()) + print(val.encode("utf-8", "backslashreplace").decode()) def showsyntaxerror(self, filename=None, running_compiled_code=False): """Display the syntax error that just occurred. diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 324599f..84bea9c 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -452,6 +452,7 @@ class InteractiveShellTestCase(unittest.TestCase): @mock.patch("builtins.print") def test_showtraceback_with_surrogates(self, mocked_print): values = [] + def mock_print_func(value, sep=" ", end="\n", file=sys.stdout, flush=False): values.append(value) if value == chr(0xD8FF): @@ -463,7 +464,7 @@ class InteractiveShellTestCase(unittest.TestCase): # ip._showtraceback() is replaced in globalipapp.py. # Call original method to test. interactiveshell.InteractiveShell._showtraceback(ip, None, None, chr(0xD8FF)) - + self.assertEqual(mocked_print.call_count, 2) self.assertEqual(values, [chr(0xD8FF), "\\ud8ff"])