summaryrefslogtreecommitdiff
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorAmmar Askar <ammar_askar@hotmail.com>2018-09-24 17:12:49 -0400
committerGuido van Rossum <guido@python.org>2018-09-24 14:12:49 -0700
commit025eb98dc0c1dc27404df6c544fc2944e0fa9f3a (patch)
treead93cb6963abd43430766fa85b629b2d5896889b /Python/symtable.c
parent223e501fb9c2b6ae21b96054e20c4c31d94a5d96 (diff)
downloadcpython-git-025eb98dc0c1dc27404df6c544fc2944e0fa9f3a.tar.gz
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/symtable.c')
-rw-r--r--Python/symtable.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 3e8c6f5dae..e7216147a8 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;
}