Show More
@@ -124,7 +124,7 b' def replacetokens(tokens, opts):' | |||
|
124 | 124 | |
|
125 | 125 | coldelta = 0 # column increment for new opening parens |
|
126 | 126 | coloffset = -1 # column offset for the current line (-1: TBD) |
|
127 | parens = [(0, 0, 0)] # stack of (line, end-column, column-offset) | |
|
127 | parens = [(0, 0, 0, -1)] # stack of (line, end-column, column-offset, type) | |
|
128 | 128 | ignorenextline = False # don't transform the next line |
|
129 | 129 | insideignoreblock = False # don't transform until turned off |
|
130 | 130 | for i, t in enumerate(tokens): |
@@ -132,11 +132,15 b' def replacetokens(tokens, opts):' | |||
|
132 | 132 | # the current line will be aligned to the last opening paren |
|
133 | 133 | # as before. |
|
134 | 134 | if coloffset < 0: |
|
135 |
|
|
|
136 |
|
|
|
137 | elif t.start[1] + 1 == parens[-1][1]: | |
|
135 | lastparen = parens[-1] | |
|
136 | if t.start[1] == lastparen[1]: | |
|
137 | coloffset = lastparen[2] | |
|
138 | elif ( | |
|
139 | t.start[1] + 1 == lastparen[1] | |
|
140 | and lastparen[3] not in (token.NEWLINE, tokenize.NL) | |
|
141 | ): | |
|
138 | 142 | # fix misaligned indent of s/util.Abort/error.Abort/ |
|
139 |
coloffset = paren |
|
|
143 | coloffset = lastparen[2] + (lastparen[1] - t.start[1]) | |
|
140 | 144 | else: |
|
141 | 145 | coloffset = 0 |
|
142 | 146 | |
@@ -164,7 +168,7 b' def replacetokens(tokens, opts):' | |||
|
164 | 168 | |
|
165 | 169 | # Remember the last paren position. |
|
166 | 170 | if _isop(i, '(', '[', '{'): |
|
167 | parens.append(t.end + (coloffset + coldelta,)) | |
|
171 | parens.append(t.end + (coloffset + coldelta, tokens[i + 1].type)) | |
|
168 | 172 | elif _isop(i, ')', ']', '}'): |
|
169 | 173 | parens.pop() |
|
170 | 174 |
@@ -215,3 +215,47 b' Test prefixed strings' | |||
|
215 | 215 | $ byteify_strings testfile.py |
|
216 | 216 | obj[b'test'] = b"1234" |
|
217 | 217 | obj[r'test'] = u"1234" |
|
218 | ||
|
219 | Test multi-line alignment | |
|
220 | ||
|
221 | $ cat > testfile.py <<'EOF' | |
|
222 | > def foo(): | |
|
223 | > error.Abort(_("foo" | |
|
224 | > "bar" | |
|
225 | > "%s") | |
|
226 | > % parameter) | |
|
227 | > { | |
|
228 | > 'test': dict, | |
|
229 | > 'test2': dict, | |
|
230 | > } | |
|
231 | > [ | |
|
232 | > "thing", | |
|
233 | > "thing2" | |
|
234 | > ] | |
|
235 | > ( | |
|
236 | > "tuple", | |
|
237 | > "tuple2", | |
|
238 | > ) | |
|
239 | > {"thing", | |
|
240 | > } | |
|
241 | > EOF | |
|
242 | $ byteify_strings testfile.py | |
|
243 | def foo(): | |
|
244 | error.Abort(_(b"foo" | |
|
245 | b"bar" | |
|
246 | b"%s") | |
|
247 | % parameter) | |
|
248 | { | |
|
249 | b'test': dict, | |
|
250 | b'test2': dict, | |
|
251 | } | |
|
252 | [ | |
|
253 | b"thing", | |
|
254 | b"thing2" | |
|
255 | ] | |
|
256 | ( | |
|
257 | b"tuple", | |
|
258 | b"tuple2", | |
|
259 | ) | |
|
260 | {b"thing", | |
|
261 | } |
General Comments 0
You need to be logged in to leave comments.
Login now