mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
bpo-34683: Make SyntaxError column offsets consistently 1-indexed (gh-9338)
Also point to start of tokens in parsing errors. Fixes bpo-34683
This commit is contained in:
parent
223e501fb9
commit
025eb98dc0
11 changed files with 65 additions and 21 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue