Patchwork [2,of,6] byteify-strings: handle triple quoted strings if they are not docstrings

login
register
mail settings
Submitter Raphaël Gomès
Date Aug. 2, 2019, 8:22 a.m.
Message ID <649e2ec4232c359d5b09.1564734133@alphare-carbon.lan>
Download mbox | patch
Permalink /patch/41125/
State Accepted
Headers show

Comments

Raphaël Gomès - Aug. 2, 2019, 8:22 a.m.
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1564732093 -7200
#      Fri Aug 02 09:48:13 2019 +0200
# Node ID 649e2ec4232c359d5b09833d8d6e1b9e309ba28a
# Parent  623f86cf8834b154cc2b7c88b6dd8378ff9481c6
# EXP-Topic byteify-strings
byteify-strings: handle triple quoted strings if they are not docstrings

As with anything in this script, this is a best effort approach. Most of the
time, when a triple quoted string is assigned to something, it's not a
docstring.

Patch

diff -r 623f86cf8834 -r 649e2ec4232c contrib/byteify-strings.py
--- a/contrib/byteify-strings.py	Fri Aug 02 09:44:11 2019 +0200
+++ b/contrib/byteify-strings.py	Fri Aug 02 09:48:13 2019 +0200
@@ -139,8 +139,10 @@ 
             # components touching docstrings need to handle unicode,
             # unfortunately.
             if s[0:3] in ("'''", '"""'):
-                yield adjusttokenpos(t, coloffset)
-                continue
+                # If it's assigned to something, it's not a docstring
+                if not _isop(i - 1, '='):
+                    yield adjusttokenpos(t, coloffset)
+                    continue
 
             # If the first character isn't a quote, it is likely a string
             # prefixing character (such as 'b', 'u', or 'r'. Ignore.