diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2014-02-17 21:45:48 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2014-02-17 21:45:48 (GMT) |
commit | 5e6db313686c200da425a54d2e0c95fa40107b1d (patch) | |
tree | 5586a30aaf9f83a3a1e2f7996773487366baa6e1 /Lib/tokenize.py | |
parent | cf626032763077bf959937705ed35f9e2b40a862 (diff) | |
download | cpython-5e6db313686c200da425a54d2e0c95fa40107b1d.zip cpython-5e6db313686c200da425a54d2e0c95fa40107b1d.tar.gz cpython-5e6db313686c200da425a54d2e0c95fa40107b1d.tar.bz2 |
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.
Diffstat (limited to 'Lib/tokenize.py')
-rw-r--r-- | Lib/tokenize.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py index 294bf9a..c156450 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -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) |