py.builtin._totext does not work with python 2.x
pytestbot opened this issue · comments
- Bitbucket: https://bitbucket.org/pytest-dev/py/issue/75
- Originally reported by: @sirex
- Originally created at: 2016-01-04T16:56:52.988
Steps to reproduce:
Run this in Python 2.7:
# coding: utf-8
import py
py.builtin._totext('bū')
Ant this will raise UnicodeDecodeRerror
.
Original comment by @sirex
Sorry for the AttributeError
, fixed the description. Yes, if uncode
receives str
it tries to decode it with ascii
.
If _totext
is equivalent for u''
literal, it should decode str
type from utf-8
. At least for Python 3.0 it does the correct thing.
Original comment by @The-Compiler
That will raise AttributeError
😉
py.buitin._totext('bū')
will be equal to unicode('bū')
, which indeed does the same.
I'm guessing because python 2 tries to encode the string as ascii and then decode it as utf-8? I'm not very familiar with the str/unicode model on python 2 though.
totext works as intended - its not a replacement for u''
strings - its casting to text be it unicode on python2 or native on python3