diff options
author | Ammar Askar <ammar_askar@hotmail.com> | 2018-09-24 21:12:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2018-09-24 21:12:49 (GMT) |
commit | 025eb98dc0c1dc27404df6c544fc2944e0fa9f3a (patch) | |
tree | ad93cb6963abd43430766fa85b629b2d5896889b /Python | |
parent | 223e501fb9c2b6ae21b96054e20c4c31d94a5d96 (diff) | |
download | cpython-025eb98dc0c1dc27404df6c544fc2944e0fa9f3a.zip cpython-025eb98dc0c1dc27404df6c544fc2944e0fa9f3a.tar.gz cpython-025eb98dc0c1dc27404df6c544fc2944e0fa9f3a.tar.bz2 |
bpo-34683: Make SyntaxError column offsets consistently 1-indexed (gh-9338)
Also point to start of tokens in parsing errors.
Fixes bpo-34683
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 2 | ||||
-rw-r--r-- | Python/compile.c | 2 | ||||
-rw-r--r-- | Python/future.c | 4 | ||||
-rw-r--r-- | Python/symtable.c | 14 |
4 files changed, 11 insertions, 11 deletions
diff --git a/Python/ast.c b/Python/ast.c index b93eb88..b2fcb21 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -683,7 +683,7 @@ ast_error(struct compiling *c, const node *n, const char *errmsg) Py_INCREF(Py_None); loc = Py_None; } - tmp = Py_BuildValue("(OiiN)", c->c_filename, LINENO(n), n->n_col_offset, loc); + tmp = Py_BuildValue("(OiiN)", c->c_filename, LINENO(n), n->n_col_offset + 1, loc); if (!tmp) return 0; errstr = PyUnicode_FromString(errmsg); diff --git a/Python/compile.c b/Python/compile.c index 707da79..3a45804 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4830,7 +4830,7 @@ compiler_error(struct compiler *c, const char *errstr) loc = Py_None; } u = Py_BuildValue("(OiiO)", c->c_filename, c->u->u_lineno, - c->u->u_col_offset, loc); + c->u->u_col_offset + 1, loc); if (!u) goto exit; v = Py_BuildValue("(zO)", errstr, u); diff --git a/Python/future.c b/Python/future.c index 4ea6827..1663a38 100644 --- a/Python/future.c +++ b/Python/future.c @@ -48,12 +48,12 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, PyObject *filename) } else if (strcmp(feature, "braces") == 0) { PyErr_SetString(PyExc_SyntaxError, "not a chance"); - PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset); + PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset + 1); return 0; } else { PyErr_Format(PyExc_SyntaxError, UNDEFINED_FUTURE_FEATURE, feature); - PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset); + PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset + 1); return 0; } } diff --git a/Python/symtable.c b/Python/symtable.c index 3e8c6f5..e721614 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -390,7 +390,7 @@ error_at_directive(PySTEntryObject *ste, PyObject *name) if (PyUnicode_Compare(PyTuple_GET_ITEM(data, 0), name) == 0) { PyErr_SyntaxLocationObject(ste->ste_table->st_filename, PyLong_AsLong(PyTuple_GET_ITEM(data, 1)), - PyLong_AsLong(PyTuple_GET_ITEM(data, 2))); + PyLong_AsLong(PyTuple_GET_ITEM(data, 2)) + 1); return 0; } @@ -990,7 +990,7 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag) PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT, name); PyErr_SyntaxLocationObject(st->st_filename, st->st_cur->ste_lineno, - st->st_cur->ste_col_offset); + st->st_cur->ste_col_offset + 1); goto error; } val |= flag; @@ -1179,7 +1179,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) e_name->v.Name.id); PyErr_SyntaxLocationObject(st->st_filename, s->lineno, - s->col_offset); + s->col_offset + 1); VISIT_QUIT(st, 0); } if (s->v.AnnAssign.simple && @@ -1274,7 +1274,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) msg, name); PyErr_SyntaxLocationObject(st->st_filename, s->lineno, - s->col_offset); + s->col_offset + 1); VISIT_QUIT(st, 0); } if (!symtable_add_def(st, name, DEF_GLOBAL)) @@ -1306,7 +1306,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) PyErr_Format(PyExc_SyntaxError, msg, name); PyErr_SyntaxLocationObject(st->st_filename, s->lineno, - s->col_offset); + s->col_offset + 1); VISIT_QUIT(st, 0); } if (!symtable_add_def(st, name, DEF_NONLOCAL)) @@ -1645,7 +1645,7 @@ symtable_visit_alias(struct symtable *st, alias_ty a) int lineno = st->st_cur->ste_lineno; int col_offset = st->st_cur->ste_col_offset; PyErr_SetString(PyExc_SyntaxError, IMPORT_STAR_WARNING); - PyErr_SyntaxLocationObject(st->st_filename, lineno, col_offset); + PyErr_SyntaxLocationObject(st->st_filename, lineno, col_offset + 1); Py_DECREF(store_name); return 0; } @@ -1736,7 +1736,7 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e, "'yield' inside generator expression"); PyErr_SyntaxLocationObject(st->st_filename, st->st_cur->ste_lineno, - st->st_cur->ste_col_offset); + st->st_cur->ste_col_offset + 1); symtable_exit_block(st, (void *)e); return 0; } |