[PATCH 1 of 6] byteify-strings: handle multi-line strings in _ensuresysstr

Raphaël Gomès raphael.gomes at octobus.net
Fri Aug 2 04:22:12 EDT 2019


# HG changeset patch
# User Raphaël Gomès <rgomes at octobus.net>
# Date 1564731851 -7200
#      Fri Aug 02 09:44:11 2019 +0200
# Node ID 623f86cf8834b154cc2b7c88b6dd8378ff9481c6
# Parent  4b04244f2d5fdc6221c29d6ae8074a81fe352c5e
# EXP-Topic byteify-strings
byteify-strings: handle multi-line strings in _ensuresysstr

The current implementation did not handle calls like

`repo.ui.log("first line"
             "other line")`

correctly.

diff -r 4b04244f2d5f -r 623f86cf8834 contrib/byteify-strings.py
--- a/contrib/byteify-strings.py	Fri Jul 26 10:47:06 2019 -0700
+++ b/contrib/byteify-strings.py	Fri Aug 02 09:44:11 2019 +0200
@@ -78,9 +78,19 @@
         already been done.
 
         """
-        st = tokens[j]
-        if st.type == token.STRING and st.string.startswith(("'", '"')):
-            sysstrtokens.add(st)
+        k = j
+        currtoken = tokens[k]
+        while currtoken.type in (token.STRING, token.NEWLINE, tokenize.NL):
+            k += 1
+            if (
+                currtoken.type == token.STRING
+                and currtoken.string.startswith(("'", '"'))
+            ):
+                sysstrtokens.add(currtoken)
+            try:
+                currtoken = tokens[k]
+            except IndexError:
+                break
 
     coldelta = 0  # column increment for new opening parens
     coloffset = -1  # column offset for the current line (-1: TBD)


More information about the Mercurial-devel mailing list