Skip to content

Commit cd54fc3

Browse files
committed
Backport the Parser/pegen.c change for a good SyntaxError to ast.c.
Fixes test_ast and test_compile.
1 parent cae5eba commit cd54fc3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Python/ast.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2460,8 +2460,25 @@ ast_for_atom(struct compiling *c, const node *n)
24602460
return NULL;
24612461
}
24622462
pynum = parsenumber(c, STR(ch));
2463-
if (!pynum)
2463+
if (!pynum) {
2464+
PyThreadState *tstate = PyThreadState_GET();
2465+
// The only way a ValueError should happen in _this_ code is via
2466+
// PyLong_FromString hitting a length limit.
2467+
if (tstate->curexc_type == PyExc_ValueError &&
2468+
tstate->curexc_value != NULL) {
2469+
PyObject *type, *value, *tb;
2470+
// This acts as PyErr_Clear() as we're replacing curexc.
2471+
PyErr_Fetch(&type, &value, &tb);
2472+
Py_XDECREF(tb);
2473+
Py_DECREF(type);
2474+
ast_error(c, ch,
2475+
"%S - Consider hexidecimal for huge integer literals "
2476+
"to avoid decimal conversion limits.",
2477+
value);
2478+
Py_DECREF(value);
2479+
}
24642480
return NULL;
2481+
}
24652482

24662483
if (PyArena_AddPyObject(c->c_arena, pynum) < 0) {
24672484
Py_DECREF(pynum);

0 commit comments

Comments
 (0)