diff -r 62438d1b11c7 Lib/test/test_long.py --- a/Lib/test/test_long.py Fri May 02 23:26:03 2014 +0200 +++ b/Lib/test/test_long.py Sat May 03 14:30:04 2014 +0200 @@ -1235,6 +1235,11 @@ class LongTest(unittest.TestCase): for n in map(int, integers): self.assertEqual(n, 0) + @support.cpython_only + def test_lshift0_id(self): + for x in (0, 10, 50, 12345, 2**100): + self.assertIs(x << 0, x) + def test_main(): support.run_unittest(LongTest) diff -r 62438d1b11c7 Objects/longobject.c --- a/Objects/longobject.c Fri May 02 23:26:03 2014 +0200 +++ b/Objects/longobject.c Sat May 03 14:30:04 2014 +0200 @@ -4118,6 +4118,12 @@ long_lshift(PyObject *v, PyObject *w) PyErr_SetString(PyExc_ValueError, "negative shift count"); return NULL; } + if (shiftby == 0) { + /* x << 0 = x */ + Py_INCREF(v); + return v; + } + /* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */ wordshift = shiftby / PyLong_SHIFT; remshift = shiftby - wordshift * PyLong_SHIFT;