Changes by Serhiy Storchaka storch...@gmail.com:
--
resolution: - fixed
stage: patch review - resolved
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23637
___
Roundup Robot added the comment:
New changeset 22e44a7ee89f by Serhiy Storchaka in branch '2.7':
Issue #23637: Showing a warning no longer fails with UnicodeErrror.
https://hg.python.org/cpython/rev/22e44a7ee89f
--
nosy: +python-dev
___
Python
Serhiy Storchaka added the comment:
One of the worst things in Python 2 is that all can work on author's machine in
ASCII-only environment, but then unhelpfully fail on user machine with
non-ASCII data. Especially when needed a combination of few conditions for the
fail. This issue is about
STINNER Victor added the comment:
Only thing required to make this work is add u in front of the message so
it is unicode.
The warnings module works with non-ASCII characters if you only use bytes
strings. I'm not sure that we should enhance it to support the unicode type in
some fields,
Serhiy Storchaka added the comment:
The problem is that the warnings module works with unicode message almost all
time except rare circumstances. So for sure this feature is used in many
programs and it works for authors and most of users. An exception can be
considered as a bug.
--
Changes by Serhiy Storchaka storch...@gmail.com:
--
assignee: - serhiy.storchaka
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23637
___
___
Serhiy Storchaka added the comment:
The problem is not only with the file.write(). If one of arguments is unicode
(even if it doesn't contain non-ascii characters) and other argument is
non-ascii string, we get this error.
warnings.showwarning(u'', DeprecationWarning, 'filè.py', 10)
Ezio Melotti added the comment:
I think that the problem is actually with the file.write() in _show_warning().
If any of the arguments of formatwarning() are unicode, the result will be
unicode, and if file (default sys.stderr) is opened in binary mode, Python
will try to encode the unicode
Serhiy Storchaka added the comment:
Here is a patch that tries to coerce non-ascii filename and line to unicode
using appropriate encoding if it is needed and possible. If it is not possible,
the warning just gets lost, as in the case of IO error.
--
keywords: +patch
stage: - patch
R. David Murray added the comment:
Can you provide a complete failure example? If message is unicode, the format
string should (in python2) be auto-promoted to unicode.
--
nosy: +r.david.murray
___
Python tracker rep...@bugs.python.org
New submission from Lukáš Němec:
File /usr/lib/python2.7/warnings.py, line 29, in _show_warning
file.write(formatwarning(message, category, filename, lineno, line))
File /usr/lib/python2.7/warnings.py, line 38, in formatwarning
s = %s:%s: %s: %s\n % (filename, lineno,
11 matches
Mail list logo