py3: use pycompat.iterbytestr to convert memoryview slice to bytestring before passing to itertools.takewhile
ClosedPublic

Authored by Kwan on Mar 8 2019, 10:00 PM.

Details

Summary

otherwise ch is the int value of the byte in py3 rather than the actual
character

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
Kwan created this revision.Mar 8 2019, 10:00 PM
yuja added a subscriber: yuja.Mar 9 2019, 8:29 PM

Queued most of the patches in this series, thanks.

  • symbol = b''.join(itertools.takewhile(lambda ch: ch not in special,
  • view[pos:])) + symbol = b''.join(pycompat.iterbytestr(itertools.takewhile( + lambda ch: ch not in special, + view[pos:]

It's probably better to apply iterbytestr() to view[pos:] so ch is
always a byte string.

Kwan updated this revision to Diff 14494.Mar 14 2019, 11:40 AM
Kwan retitled this revision from py3: use pycompat.iterbytestr to convert itertools.takewhile result back to bytes to py3: use pycompat.iterbytestr to convert memoryview slice to bytestring before passing to itertools.takewhile.
Kwan edited the summary of this revision. (Show Details)
Kwan added a comment.Mar 14 2019, 11:41 AM
In D6103#88988, @yuja wrote:

Queued most of the patches in this series, thanks.

-        symbol = b''.join(itertools.takewhile(lambda ch: ch not in special,
-                                              view[pos:]))
+        symbol = b''.join(pycompat.iterbytestr(itertools.takewhile(
+            lambda ch: ch not in special,
+            view[pos:]

It's probably better to apply iterbytestr() to view[pos:] so ch is
always a byte string.

Thanks, done!

This revision was automatically updated to reflect the committed changes.