]> granicus.if.org Git - python/commitdiff
Do not reset the line number because we already set file position to correct
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 9 Jan 2014 18:12:49 +0000 (20:12 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 9 Jan 2014 18:12:49 +0000 (20:12 +0200)
value.

(fixes error in patch for issue #18960)

Lib/test/test_traceback.py
Parser/tokenizer.c

index 5bce2af68a960df8fb5e126d3c7e86bbe5483598..bca825de43bf2fb75a8512024a6a1380c2a5aa7d 100644 (file)
@@ -146,6 +146,10 @@ class SyntaxTracebackCases(unittest.TestCase):
                     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):
index a69d7880da7ab2bf7d3de66bb1595dbb5ae80140..8530723c266dcd382097380ad322f8383c75d49f 100644 (file)
@@ -514,14 +514,6 @@ fp_setreadl(struct tok_state *tok, const char* enc)
     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);