Index: Lib/test/test_compile.py =================================================================== --- Lib/test/test_compile.py (revision 42950) +++ Lib/test/test_compile.py (working copy) @@ -211,6 +211,10 @@ self.assertEqual(eval("-" + all_one_bits), -18446744073709551615L) else: self.fail("How many bits *does* this machine have???") + #verify treatment of contant folding on -(sys.maxint+1) + # i.e. -2147483648 on 32 bit platforms. Should return int, not long + self.assertEqual(type(eval("-%s" % (sys.maxint + 1))), int) + self.assertEqual(type(eval("-%s" % (sys.maxint + 2))), long) def test_sequence_unpacking_error(self): # Verify sequence packing/unpacking with "or". SF bug #757818 Index: Python/compile.c =================================================================== --- Python/compile.c (revision 42950) +++ Python/compile.c (working copy) @@ -557,6 +557,7 @@ PyObject *newconst=NULL, *v; Py_ssize_t len_consts; int opcode; + long sysMinInt; /* Pre-conditions */ assert(PyList_CheckExact(consts)); @@ -568,8 +569,22 @@ switch (opcode) { case UNARY_NEGATIVE: /* Preserve the sign of -0.0 */ - if (PyObject_IsTrue(v) == 1) + if (PyObject_IsTrue(v) == 1) { newconst = PyNumber_Negative(v); + if(newconst && newconst->ob_type == &PyLong_Type) { + /* Work around for -(sys.maxInt+1) as constant + SF Bug 1441486. If we have a long, and it + can become an int, do it*/ + sysMinInt = PyLong_AsLong(newconst); + if(!PyErr_Occurred()) { + newconst = PyInt_FromLong(sysMinInt); + } + else if (PyErr_Occurred() == PyExc_OverflowError) { + PyErr_Clear(); + } + } + } + break; case UNARY_CONVERT: newconst = PyObject_Repr(v);