[pypy-issue] Issue #2699: warnings.warn fails with non-ascii unicode strings on PyPy2 5.9.0 (pypy/pypy)
Bruno Oliveira
issues-reply at bitbucket.org
Thu Nov 9 16:01:56 EST 2017
New issue 2699: warnings.warn fails with non-ascii unicode strings on PyPy2 5.9.0
https://bitbucket.org/pypy/pypy/issues/2699/warningswarn-fails-with-non-ascii-unicode
Bruno Oliveira:
Hi,
`warnings.warn` in recent versions breaks when passed `non-ascii` unicode on Windows:
```python
# -*- coding: utf8 -*-
import warnings
warnings.warn(u"测试")
```
Running this produces this output:
```
C:\pytest\.pypy\bin\pypy.exe C:/pytest/.tmp/test_pypy_unicode.py
Traceback (most recent call last):
File "C:/pytest/.tmp/test_pypy_unicode.py", line 3, in <module>
warnings.warn(u"测试")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
```
I'm not sure in which version this started to break, but we detected this on the pytest's test suite when a test started to break all of sudden. [Here's a link](https://ci.appveyor.com/project/pytestbot/pytest/build/1.0.3355/job/1sfgibpuk38ol3i4) to one of the AppVeyor failures.
Interestingly, running the same code under CPython does not produce **any** output and returns zero to the OS.
But if we change the string to something `ascii` compatible, than both CPython and PyPy print the correct output:
```
pypy .tmp\test_pypy_unicode.py
.tmp\test_pypy_unicode.py:4: UserWarning: foo
warnings.warn('foo')
```
```
python.exe .tmp\test_pypy_unicode.py
.tmp\test_pypy_unicode.py:4: UserWarning: foo
warnings.warn('foo')
```
**PyPy2 version info**
```
pypy --version
Python 2.7.13 (c2437cf9b7f1, Sep 24 2017, 17:23:53)
[PyPy 5.9.0 with MSC v.1500 32 bit]
```
Thanks for all the hard work!
More information about the pypy-issue
mailing list