[Python-checkins] cpython (3.3): Do not reset the line number because we already set file position to correct

serhiy.storchaka python-checkins at python.org
Thu Jan 9 19:14:17 CET 2014


http://hg.python.org/cpython/rev/875a514671dd
changeset:   88373:875a514671dd
branch:      3.3
parent:      88370:fafac90b69c4
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Jan 09 20:12:49 2014 +0200
summary:
  Do not reset the line number because we already set file position to correct
value.

(fixes error in patch for issue #18960)

files:
  Lib/test/test_traceback.py |  4 ++++
  Parser/tokenizer.c         |  8 --------
  2 files changed, 4 insertions(+), 8 deletions(-)


diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -146,6 +146,10 @@
                     text, charset, 4)
             do_test("#!shebang\n# coding: {0}\n".format(charset),
                     text, charset, 5)
+            do_test(" \t\f\n# coding: {0}\n".format(charset),
+                    text, charset, 5)
+        # Issue #18960: coding spec should has no effect
+        do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
 
 
 class TracebackFormatTests(unittest.TestCase):
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -514,14 +514,6 @@
     readline = _PyObject_GetAttrId(stream, &PyId_readline);
     tok->decoding_readline = readline;
 
-    /* The file has been reopened; parsing will restart from
-     * the beginning of the file, we have to reset the line number.
-     * But this function has been called from inside tok_nextc() which
-     * will increment lineno before it returns. So we set it -1 so that
-     * the next call to tok_nextc() will start with tok->lineno == 0.
-     */
-    tok->lineno = -1;
-
   cleanup:
     Py_XDECREF(stream);
     Py_XDECREF(io);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list