Untokenize: An logically incorrect assert tested user input validity.

Replace it with correct logic that raises ValueError for bad input.
Issues #8478 and #12691 reported the incorrect logic.
Add an Untokenize test case and an initial test method.
This commit is contained in:
Terry Jan Reedy 2014-02-17 16:45:48 -05:00
parent cf62603276
commit 5e6db31368
2 changed files with 18 additions and 2 deletions

View file

@ -229,7 +229,9 @@ class Untokenizer:
def add_whitespace(self, start):
row, col = start
assert row <= self.prev_row
if row < self.prev_row or row == self.prev_row and col < self.prev_col:
raise ValueError("start ({},{}) precedes previous end ({},{})"
.format(row, col, self.prev_row, self.prev_col))
col_offset = col - self.prev_col
if col_offset:
self.tokens.append(" " * col_offset)