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

Authored by Kwan on Fri, Mar 8, 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
Lint Skipped
Unit
Unit Tests Skipped
Kwan created this revision.Fri, Mar 8, 10:00 PM
yuja added a subscriber: yuja.Sat, Mar 9, 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.Thu, Mar 14, 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.Thu, Mar 14, 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.