cpython: 0f0e9b7d4f1d (original) (raw)

Mercurial > cpython

changeset 89352:0f0e9b7d4f1d 2.7

Issue #9974: When untokenizing, use row info to insert backslash+newline. Original patches by A. Kuchling and G. Rees (#12691). [#9974]

Terry Jan Reedy tjreedy@udel.edu
date Sun, 23 Feb 2014 23:32:59 -0500
parents a9464e900705
children 0e77dd295a88 fadde95c134e
files Lib/test/test_tokenize.py Lib/tokenize.py
diffstat 2 files changed, 21 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_tokenize.py 16 Lib/tokenize.py 6

line wrap: on

line diff

--- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -4,7 +4,7 @@ Tests for the tokenize module. >>> import glob, random, sys The tests can be really simple. Given a small fragment of source -code, print out a table with tokens. The ENDMARK is omitted for +code, print out a table with tokens. The ENDMARKER is omitted for brevity. >>> dump_tokens("1 + 1") @@ -618,6 +618,7 @@ def decistmt(s): class UntokenizeTest(TestCase): def test_bad_input_order(self):

@@ -625,8 +626,21 @@ class UntokenizeTest(TestCase): u.add_whitespace((1,3)) self.assertEqual(cm.exception.args[0], 'start (1,3) precedes previous end (2,2)')

+ def test_iter_compat(self): u = Untokenizer() token = (NAME, 'Hello')

--- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -188,6 +188,10 @@ class Untokenizer: 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))

@@ -199,6 +203,8 @@ class Untokenizer: self.compat(t, it) break tok_type, token, start, end, line = t