Index: Lib/test/test_compile.py =================================================================== --- Lib/test/test_compile.py (revision 43162) +++ 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 43162) +++ Python/compile.c (working copy) @@ -570,8 +570,18 @@ 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 && PyLong_CheckExact(newconst)) { + /* Work around for -(sys.maxInt+1) as constant + If it's a long, and can be an int, do it. */ + long 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);