Code review comment for lp:~songofacandy/bzr/i18n-utextwrap

Martin Packman (gz) wrote :

Okay, nearly there. Two tests from textwrapper that use `fix_sentence_endings=True` fail because of this code in the textwrap module which puts bytestrings in the chunks list:

    if chunks[i+1] == " " and pat.search(chunks[i]):
        chunks[i+1] = " "

Resulting in errors like:

Traceback (most recent call last):
  ...
  File "...\lib\test\test_textwrap.py", line 102, in test_fix_sentence_endings
    self.check(wrapper.wrap(text), expect)
  File "...\i18n-utextwrap\bzrlib\utextwrap.py", line 216, in wrap
    return textwrap.TextWrapper.wrap(self, unicode(text))
  File "...\lib\textwrap.py", line 321, in wrap
    return self._wrap_chunks(chunks)
  File "...\i18n-utextwrap\bzrlib\utextwrap.py", line 172, in _wrap_chunks
    l = self._width(chunks[-1])
  File "...\i18n-utextwrap\bzrlib\utextwrap.py", line 95, in _width
    return sum(charwidth(c) for c in s)
  File "...\i18n-utextwrap\bzrlib\utextwrap.py", line 95, in <genexpr>
    return sum(charwidth(c) for c in s)
  File "...\i18n-utextwrap\bzrlib\utextwrap.py", line 86, in _unicode_char_width
    return (_eawidth(uc) in self._east_asian_doublewidth and 2) or 1
TypeError: must be unicode, not str

Annoying. That option is pretty bogus anyway, I'd not mind just not supporting it. Otherwise _fix_sentence_endings needs overriding so it doesn't mix up types in the chunks list.

« Back to merge proposal