Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58e8761

Browse files
committed
Issue #13436: Fix a bogus error message when an AST object was passed
an invalid integer value.
1 parent 3b1acf1 commit 58e8761

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

Lib/test/test_ast.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,17 @@ def test_literal_eval_issue4907(self):
486486
self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j)
487487
self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j)
488488

489+
def test_bad_integer(self):
490+
# issue13436: Bad error message with invalid numeric values
491+
body = [ast.ImportFrom(module='time',
492+
names=[ast.alias(name='sleep')],
493+
level=None,
494+
lineno=None, col_offset=None)]
495+
mod = ast.Module(body)
496+
with self.assertRaises(ValueError) as cm:
497+
compile(mod, 'test', 'exec')
498+
self.assertIn("invalid integer value: None", str(cm.exception))
499+
489500

490501
def test_main():
491502
support.run_unittest(AST_Tests, ASTHelpers_Test)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #13436: Fix a bogus error message when an AST object was passed
14+
an invalid integer value.
15+
1316
- Issue #13338: Handle all enumerations in _Py_ANNOTATE_MEMORY_ORDER
1417
to allow compiling extension modules with -Wswitch-enum on gcc.
1518
Initial patch by Floris Bruynooghe.

Parser/asdl_c.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,7 @@ def visitModule(self, mod):
816816
{
817817
int i;
818818
if (!PyLong_Check(obj)) {
819-
PyObject *s = PyObject_Repr(obj);
820-
if (s == NULL) return 1;
821-
PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
822-
PyBytes_AS_STRING(s));
823-
Py_DECREF(s);
819+
PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
824820
return 1;
825821
}
826822

0 commit comments

Comments
 (0)