From 3b1acf11e98bceec44c28d9e6d665e68227d8bf2 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Tue, 22 Nov 2011 19:34:08 +0100 Subject: bytes() can't be used to get a representation of an object. --- Doc/library/exceptions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 528febd..ca3ad3e 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -40,9 +40,9 @@ The following exceptions are used mostly as base classes for other exceptions. 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 -- cgit v0.12 From 58e8761da6d11653288b76d2dec6417000a20e74 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Tue, 22 Nov 2011 21:51:55 +0100 Subject: Issue #13436: Fix a bogus error message when an AST object was passed an invalid integer value. --- Lib/test/test_ast.py | 11 +++++++++++ Misc/NEWS | 3 +++ Parser/asdl_c.py | 6 +----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 2ba3ea5..be9f05e 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 4e43b45..0b228ef 100644 --- 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. diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 249e18d..b85c07e 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -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; } -- cgit v0.12 From 5e8f8104116edfcbfee2690a58391830bd9883ae Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Tue, 22 Nov 2011 21:52:30 +0100 Subject: Issue #13436: commit regenerated Python-ast.c --- Python/Python-ast.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 89c07cd..a276b6c 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -622,11 +622,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; } -- cgit v0.12