Fix bug with non-ascii reprs inside pretty-printed lists. #600

Merged
merged 4 commits into from Jul 22, 2011

3 participants

@takluyver
IPython member

An ugly but simple fix for a bug with non-ascii reprs. Ideally we'd use unicode in IPython.lib.pretty, but that's a bigger change, and would probably introduce further bugs.

Closes gh-597 (@juliantaylor)

@juliantaylor

I suggest adding a test so the bug doesn't creep back in when it will be fixed properly:
http://paste.ubuntu.com/648445/

@takluyver
IPython member
@takluyver
IPython member

Thanks @juliantaylor, I've added it to the pull request.

@fperez fperez commented on the diff Jul 22, 2011
IPython/core/tests/test_interactiveshell.py
@@ -112,5 +112,11 @@ class InteractiveShellTestCase(unittest.TestCase):
ip = get_ipython()
ip.run_cell('!(true)\n', False)
ip.run_cell('!(true)\n\n\n', False)
-
-
+
+ def test_gh_597(self):
@fperez
IPython member
fperez added a note Jul 22, 2011

perhaps add a short docstring briefly explaining what the problem being caught was, so we don't depend on a GH url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fperez fperez commented on an outdated diff Jul 22, 2011
IPython/core/formatters.py
@@ -433,7 +433,7 @@ class PlainTextFormatter(BaseFormatter):
# This uses use StringIO, as cStringIO doesn't handle unicode.
stream = StringIO()
printer = pretty.RepresentationPrinter(stream, self.verbose,
- self.max_width, self.newline,
+ self.max_width, self.newline.encode(),
@fperez
IPython member
fperez added a note Jul 22, 2011

Add a comment to explain why the encode() call is necessary here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fperez
IPython member

After discussion on irc, this is good to go before release. Very localized, safe and necessary fix.

@takluyver takluyver merged commit b924107 into ipython:master Jul 22, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment