Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Backport the Parser/pegen.c change for a good SyntaxError to ast.c.
Fixes test_ast and test_compile.
  • Loading branch information
gpshead committed Aug 30, 2022
commit cd54fc39876a1de6853a8cf436b4b5ae6778f5a3
19 changes: 18 additions & 1 deletion Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2460,8 +2460,25 @@ ast_for_atom(struct compiling *c, const node *n)
return NULL;
}
pynum = parsenumber(c, STR(ch));
if (!pynum)
if (!pynum) {
PyThreadState *tstate = PyThreadState_GET();
// The only way a ValueError should happen in _this_ code is via
// PyLong_FromString hitting a length limit.
if (tstate->curexc_type == PyExc_ValueError &&
tstate->curexc_value != NULL) {
PyObject *type, *value, *tb;
// This acts as PyErr_Clear() as we're replacing curexc.
PyErr_Fetch(&type, &value, &tb);
Py_XDECREF(tb);
Py_DECREF(type);
ast_error(c, ch,
"%S - Consider hexidecimal for huge integer literals "
"to avoid decimal conversion limits.",
value);
Py_DECREF(value);
}
return NULL;
}

if (PyArena_AddPyObject(c->c_arena, pynum) < 0) {
Py_DECREF(pynum);
Expand Down