encoding does not work when using StringIO under Python 2
tkeffer opened this issue · 4 comments
tkeffer commented
Consider the following:
Python 2.7.16 (default, Nov 9 2019, 05:55:08)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from StringIO import StringIO
>>> import configobj
>>> print(configobj.__version__)
5.0.6
>>> s = StringIO("temperature = 20°C")
>>> c = configobj.ConfigObj(s, encoding='utf-8')
>>> c['temperature']
'20\xc2\xb0C'
>>> type(c['temperature'])
<type 'str'>
Under Python 2, my expectation is that the type would be Unicode, not str
.
Or, am I missing something?
robdennis commented
this is at least unit testable so I'll look into it. At this exact second I don't actually know what the expected result should be.
tkeffer commented
I would expect the resuts to be
>>> c['temperature']
u'20\xb0C'
>>> type(c['temperature'])
<type 'unicode'>
robdennis commented
This is helpful thank you. I was imprecise and I meant this as also a "I need to remember what the code does when the encoding keyword argument is provided".
Optimistically putting this in 5.1.0 even though it's not clear what options we have for building 2.x distributables
tkeffer commented
It's been over 3 years since Python 2.7 end of life. No one would give you grief if you simply dropped support.