File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
490501def test_main ():
491502 support .run_unittest (AST_Tests , ASTHelpers_Test )
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ What's New in Python 3.2.3?
1010Core 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.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments