Commit 75ddcc7
committed
fix: do not treat blank lines with trailing whitespace as line continuations
A blank line that contains trailing whitespace (e.g. " \n") produces an
NL token whose `.line` is not exactly "\n" or "\r\n". The guard in
`is_newline_continuation` only excluded the exact-blank forms, so such a
line was misclassified as a continuation of the preceding line. This
caused `_do_update_token_indices` to rewrite the token's start row back to
the previous token's end row, yielding a start position that precedes the
previous token's end. `tokenize.untokenize` then raised
`ValueError: start (r,c) precedes previous end (r,c)` and docformatter
crashed (regression from the stdlib tokenize migration in #325, v1.7.8).
Classify any whitespace-only line as blank by testing `token.line.strip()`
instead of comparing the raw line against {"\n", "\r\n"}. Genuine
continuations (whose stripped line is non-empty) are unaffected.
Fixes #355.1 parent ead6248 commit 75ddcc7
3 files changed
Lines changed: 9 additions & 1 deletion
File tree
- src/docformatter
- tests
- _data/string_files
- formatter
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
442 | 443 | | |
443 | | - | |
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1244 | 1244 | | |
1245 | 1245 | | |
1246 | 1246 | | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| |||
0 commit comments