Issue #13436: Fix a bogus error message when an AST object was passed
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 22 Nov 2011 20:51:55 +0000 (21:51 +0100)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Tue, 22 Nov 2011 20:51:55 +0000 (21:51 +0100)
an invalid integer value.

Lib/test/test_ast.py
Misc/NEWS
Parser/asdl_c.py

index 2ba3ea552d4d54f9b26f0ddabb58ac2bf936d9f7..be9f05eb46601cca38b33233f6620761d9c7c3a5 100644 (file)
@@ -486,6 +486,17 @@ class ASTHelpers_Test(unittest.TestCase):
         self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j)
         self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j)
 
+    def test_bad_integer(self):
+        # issue13436: Bad error message with invalid numeric values
+        body = [ast.ImportFrom(module='time',
+                               names=[ast.alias(name='sleep')],
+                               level=None,
+                               lineno=None, col_offset=None)]
+        mod = ast.Module(body)
+        with self.assertRaises(ValueError) as cm:
+            compile(mod, 'test', 'exec')
+        self.assertIn("invalid integer value: None", str(cm.exception))
+
 
 def test_main():
     support.run_unittest(AST_Tests, ASTHelpers_Test)
index 4e43b4546af4c010150e8a22acb74eb7d4e4d7cb..0b228ef14bce4661c6c3b03cc311ef1da164deed 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.3?
 Core and Builtins
 -----------------
 
+- Issue #13436: Fix a bogus error message when an AST object was passed
+  an invalid integer value.
+
 - Issue #13338: Handle all enumerations in _Py_ANNOTATE_MEMORY_ORDER
   to allow compiling extension modules with -Wswitch-enum on gcc.
   Initial patch by Floris Bruynooghe.
index 249e18ddf42494fbcf93dd5822b0d698008f02fc..b85c07ec1b0b71af4deb6a8a16aef11545b09854 100755 (executable)
@@ -816,11 +816,7 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
 {
     int i;
     if (!PyLong_Check(obj)) {
-        PyObject *s = PyObject_Repr(obj);
-        if (s == NULL) return 1;
-        PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
-                     PyBytes_AS_STRING(s));
-        Py_DECREF(s);
+        PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
         return 1;
     }