[Python-checkins] cpython (merge 3.2 -> default): Merge branch 3.2

amaury.forgeotdarc python-checkins at python.org
Tue Nov 22 22:02:18 CET 2011


http://hg.python.org/cpython/rev/53cc2668d54f
changeset:   73701:53cc2668d54f
parent:      73697:77ab830930ae
parent:      73700:470f7d7c57ce
user:        Amaury Forgeot d'Arc <amauryfa at gmail.com>
date:        Tue Nov 22 22:02:01 2011 +0100
summary:
  Merge branch 3.2

files:
  Doc/library/exceptions.rst |   6 +++---
  Lib/test/test_ast.py       |  11 +++++++++++
  Misc/NEWS                  |   3 +++
  Parser/asdl_c.py           |   6 +-----
  Python/Python-ast.c        |   6 +-----
  5 files changed, 19 insertions(+), 13 deletions(-)


diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -44,9 +44,9 @@
 
    The base class for all built-in exceptions.  It is not meant to be directly
    inherited by user-defined classes (for that, use :exc:`Exception`).  If
-   :func:`bytes` or :func:`str` is called on an instance of this class, the
-   representation of the argument(s) to the instance are returned, or the empty
-   string when there were no arguments.
+   :func:`str` is called on an instance of this class, the representation of
+   the argument(s) to the instance are returned, or the empty string when
+   there were no arguments.
 
    .. attribute:: args
 
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -491,6 +491,17 @@
         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))
+
 
 class ASTValidatorTests(unittest.TestCase):
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #13436: Fix a bogus error message when an AST object was passed
+  an invalid integer value.
+
 - Issue #13411: memoryview objects are now hashable when the underlying
   object is hashable.
 
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -844,11 +844,7 @@
 {
     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;
     }
 
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -690,11 +690,7 @@
 {
     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;
     }
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list