-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unicode line crashes traceback print #9126
Comments
What's |
Current IPython is 4.0.1, do you see this error with 4.0? |
Sorry, my fault. I updated the reproducer. I got this error, when I was doing tests on a ZODB from ipython. The ft buffer comes from within the library, so not really my choice. I didn't test it on ipython 4.0, just with this somewhat deprecated ubuntu default. |
I guess we're putting some unicode into linecache. We handle all source code as unicode. You can work around this for Python 2 by defining a custom IO class that accepts bytes or unicode: from io import StringIO
from IPython.utils import py3compat
class MyStringIO(StringIO):
def write(self, s):
s = py3compat.cast_unicode(s, encoding=DEFAULT_ENCODING)
super(MyStringIO, self).write(s) You can also mostly get by with StringIO.StringIO, but in some situations it will start throwing UnicodeErrors back at you. Or just use Python 3. Closing as I don't think we're going to change anything here. |
Well, I surely understand something like, "it's an edge case and no one cares about it" as a reason to close this. But recommending py3 and using unicode as a default, irrespectively of py2 or py3, is some kind of deprecating py2. And that would actually be quite a pity. |
We know that some people care about it, but the possible fixes either break something that more people care about, or add too much extra complexity (I have a fantastic scheme that involves parsing the code twice and playing with the AST, but I really don't want to be responsible for it). |
Running this code from the ipython shell (2.3.0) and python 2.7.10:
Instead of properly printing the traceback get a TypeError:
Turns out, the last traceback line is formatted as unicode, instead of str like the other lines. Any ideas on that?
The text was updated successfully, but these errors were encountered: