Closed simplylizz closed 4 years ago
Here is correct fix:
def __repr__(self):
return "l{0}".format(repr(text_type(self)).lstrip('u'))
...and some tests:
def test_lazy_repr(self):
string = repr(lazy_gettext(u'Азино 777'))
if PY2:
assert string == r"l'\u0410\u0437\u0438\u043d\u043e 777'"
else:
assert string == "l'Азино 777'"
string = repr(lazy_gettext(u'Azino 777'))
assert string == "l'Azino 777'"
string = repr(lazy_gettext('Azino 777'))
assert string == "l'Azino 777'"
Please note Py2 is no longer supported as of version 2.0.0.
LazyString.__repr__
callsstr.format
and if the argument is unicode string with non-ascii symbols then it throwsUnicodeEncodeError
.How to reproduce:
Perhaps you could fix this with by replacing inside
__repr__
str.format
call onunicode.format
or just by using%s
-based formatting which handles such situations without exceptions: