comparison contrib/byteify-strings.py @ 42675:e9592e113c31

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.
author Raphaël Gomès <rgomes@octobus.net>
date Fri, 02 Aug 2019 09:48:13 +0200
parents 70bd1965bd07
children b9a200477edf
comparison
equal deleted inserted replaced
42674:70bd1965bd07 42675:e9592e113c31
137 # is b''' prefixed, leading to a SyntaxError. We leave all 137 # is b''' prefixed, leading to a SyntaxError. We leave all
138 # docstrings as unprefixed to avoid this. This means Mercurial 138 # docstrings as unprefixed to avoid this. This means Mercurial
139 # components touching docstrings need to handle unicode, 139 # components touching docstrings need to handle unicode,
140 # unfortunately. 140 # unfortunately.
141 if s[0:3] in ("'''", '"""'): 141 if s[0:3] in ("'''", '"""'):
142 yield adjusttokenpos(t, coloffset) 142 # If it's assigned to something, it's not a docstring
143 continue 143 if not _isop(i - 1, '='):
144 yield adjusttokenpos(t, coloffset)
145 continue
144 146
145 # If the first character isn't a quote, it is likely a string 147 # If the first character isn't a quote, it is likely a string
146 # prefixing character (such as 'b', 'u', or 'r'. Ignore. 148 # prefixing character (such as 'b', 'u', or 'r'. Ignore.
147 if s[0] not in ("'", '"'): 149 if s[0] not in ("'", '"'):
148 yield adjusttokenpos(t, coloffset) 150 yield adjusttokenpos(t, coloffset)