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

INADA Naoki (songofacandy) wrote :

On Sat, May 14, 2011 at 10:04 PM, Martin [gz] <email address hidden> 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.

I've overrided the _fix_sentence_endings.

Why I miss the error is I used another Python environment when
removing cast to unicode.
To avoid this, I've added empty test case that raises TestSkipped when
test.test_textwrap
is unavailable.

> --
> https://code.launchpad.net/~songofacandy/bzr/i18n-utextwrap/+merge/59950
> You are the owner of lp:~songofacandy/bzr/i18n-utextwrap.
>

--
INADA Naoki  <email address hidden>

« Back to merge proposal