Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1064a13

Browse files
Do not reset the line number because we already set file position to correct
value. (fixes error in patch for issue #18960)
1 parent 50b82c7 commit 1064a13

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

Lib/test/test_traceback.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def do_test(firstlines, message, charset, lineno):
146146
text, charset, 4)
147147
do_test("#!shebang\n# coding: {0}\n".format(charset),
148148
text, charset, 5)
149+
do_test(" \t\f\n# coding: {0}\n".format(charset),
150+
text, charset, 5)
151+
# Issue #18960: coding spec should has no effect
152+
do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
149153

150154

151155
class TracebackFormatTests(unittest.TestCase):

Parser/tokenizer.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,6 @@ fp_setreadl(struct tok_state *tok, const char* enc)
514514
readline = _PyObject_GetAttrId(stream, &PyId_readline);
515515
tok->decoding_readline = readline;
516516

517-
/* The file has been reopened; parsing will restart from
518-
* the beginning of the file, we have to reset the line number.
519-
* But this function has been called from inside tok_nextc() which
520-
* will increment lineno before it returns. So we set it -1 so that
521-
* the next call to tok_nextc() will start with tok->lineno == 0.
522-
*/
523-
tok->lineno = -1;
524-
525517
cleanup:
526518
Py_XDECREF(stream);
527519
Py_XDECREF(io);

0 commit comments

Comments
 (0)