Skip to content
This repository

Correct string type casting in pinfo. #1178

Merged
merged 1 commit into from over 2 years ago

3 participants

Thomas Kluyver Min RK Fernando Perez
Thomas Kluyver
Collaborator

Haven't got time to work out a test at the moment, but this fixes #1177, and I don't believe it can introduce any failures that weren't already present.

Closes gh-1177

Min RK
Owner

Seems quite straightforward. I don't see any way for this to cause a problem, since the only case affected is bytes in on Python 2, which was already wrong. In all other cases, cast_bytes_py2 is identical to unicode_to_str.

A test would be great, but go ahead and merge if it's not feasible.

Thomas Kluyver
Collaborator

It should be possible to do a test, but I'm not going to get round to it tonight. Since we've both come to the same conclusion about this, I'll merge it so it gets into 0.12, and open an issue to remind me to write a test.

Min RK
Owner

sounds good.

Thomas Kluyver takluyver merged commit a85c230 into from
Thomas Kluyver takluyver closed this
Fernando Perez
Owner

OK, I agree. The change is clean and I also tested that with xlrd installed (ubuntu package python-xlrd), the bug is there in master and gets fixed by this. A simple test would be to create a temp file with cp1252 encoding that contains just

# coding: cp-1252
def f():
  "<problematic chars here>"

and then do in the test the equivalent of %run tempfile; get_ipython().inspector.info(f, detail_level=1).

But @takluyver, it's no problem if that test is added later on; go ahead and merge this even if you can't add the test now.

Note: @minrk made a good point about not rebasing even single-commit PRs, so that we can clearly see in the log those things that got reviewed and merged as PRs as opposed to direct commits. After that conversation, I've gotten into the habit of using the green button on this page, and simply copying (and editing for clarity as needed) the original PR message, including the closing directive.

Fernando Perez
Owner

Well, you were faster than me :) Glad we were saying the same thing!

Thomas Kluyver
Collaborator
Fernando Perez
Owner

No worries; we've done a ton of even forced ff (via rebasing), so there's no big harm here. But the idea seemed sensible, so we can adopt it for the future.

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

Showing 1 unique commit by 1 author.

Dec 18, 2011
Thomas Kluyver Correct string type casting in pinfo.
Closes gh-1177
a85c230
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  IPython/core/oinspect.py
2  IPython/core/oinspect.py
@@ -457,7 +457,7 @@ def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0):
457 457
         # Source or docstring, depending on detail level and whether
458 458
         # source found.
459 459
         if detail_level > 0 and info['source'] is not None:
460  
-            displayfields.append(("Source", self.format(py3compat.unicode_to_str(info['source']))))
  460
+            displayfields.append(("Source", self.format(py3compat.cast_bytes_py2(info['source']))))
461 461
         elif info['docstring'] is not None:
462 462
             displayfields.append(("Docstring", info["docstring"]))
463 463
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.