-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Silent crash when exec produces a syntax error involving Unicode #520
Comments
This seems to work as expected under Python 3 (with the addition of parentheses for exec). Input:
Output:
Under Python 2, I get the crash, but it's not quiet as I get
Output:
|
The problem seems to be in py.code: Input: import py
try:
exec u'''foo u"\u03b1"'''
except Exception as e:
info = py.code.ExceptionInfo()
print info.exconly() Output:
The issue seems to be that py.code has its own copy of format_exception_only that tries to return unicode (which fails when code.py tries to join them). [' File "<string>", line 1\n', ' foo u"\xce\xb1"\n', ' ^\n', u'SyntaxError: invalid syntax\n']
[<type 'str'>, <type 'str'>, <type 'str'>, <type 'unicode'>] Output:
However, in this case we get a mixture of unicode and utf-8 encoded strings. This is because |
Exec is not the only way to get this error. Importing a non-ascii file with a syntax error has the same result: Input: import py
try:
import bad
except Exception as e:
info = py.code.ExceptionInfo()
print info.exconly() bad.py # coding: utf-8
foo 'é' Output
|
Fixed in #578 |
Originally reported by: Kodi Arfer (BitBucket: Kodiologist, GitHub: Kodiologist)
Input:
Output:
(Except the output has no trailing newline, just a trailing space after
test_something.py
.)Using
--assert=plain
makes no difference.The text was updated successfully, but these errors were encountered: