unidecode icon indicating copy to clipboard operation
unidecode copied to clipboard

BUG: `newbytes` objects (`future.builtins.str` objects) are wrongly `repr`ed by unidecode

Open hobson opened this issue 9 years ago • 0 comments

Punchline: from builtins import str; str(unidecode(str('2b or not 2b')))

"b'2b or not 2b'"

>>> from unidecode import unidecode
>>> str(unidecode(str('2b or not 2b')))  # no problem
'2b or not 2b'
>>> from builtins import str
>>> str(unidecode(str('2b or not 2b')))  # big problem
"b'2b or not 2b'"
>>> str(str('2b or not 2b'))  # str recursively all you want
'2b or not 2b'
>>> unidecode(str('2b or not 2b'))  # `newbyte` obj is `repr`ed by unidecode
b'2b or not 2b'
>>> unidecode('2b or not 2b')
'2b or not 2b'
>>> unidecode(unidecode('2b or not 2b'))
'2b or not 2b'
>>> unidecode(unidecode(b'2b or not 2b'))
'2b or not 2b'
>>> unidecode(unidecode(str('2b or not 2b')))  # because future.builtins creates a newbytes type
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
...
AttributeError: encode method has been disabled in newbytes
>>> unidecode(str('2b or not 2b'))
b'2b or not 2b'

hobson avatar Aug 23 '16 18:08 hobson