Problem with StreamReaderWriter on 3.6.3?

Peter pacqa100 at yahoo.com.au
Thu Oct 19 17:46:53 EDT 2017


I came across this code in Google cpplint.py, a Python script for 
linting C++ code. I was getting funny results with Python 3.6.3, but it 
worked fine under 2.7.13

I've tracked the problem to an issue with StreamReaderWriter; the 
traceback and error never shows under 3. The _cause_ of the error is 
clear (xrange not in Py3), but I need the raised exception to show.

I'm running Python 3.6.3 32bit on Windows 10. I also get the same 
results on Python 3.5.2 on Ubuntu (under WSL)

I'm not super familiar with rebinding stderr with codecs, but I'm 
guessing they are doing it because of some Unicode issue they may have 
been having.

I have a workaround - drop the rebinding - but it seems like there might 
be an error in StreamReaderWriter.
Do other people see the same behaviour?
Is there something I'm not seeing or understanding?
Would I raise it on issue tracker?

Peter

----------------------------------------------------------

import sys
import codecs

sys.stderr = codecs.StreamReaderWriter(
     sys.stderr, codecs.getreader('utf8'), codecs.getwriter('utf8'), 
'replace')

# This should work fine in Py 2, but raise an exception in Py3
# But instead Py3 "swallows" the exception and it is never seen
print(xrange(1, 10))

# Although this line doesn't show in Py 3 (as the script has silently 
crashed)
print("This line doesn't show in Py 3")

----------------------------------------------------------








More information about the Python-list mailing list