Index: Python/ceval.c =================================================================== --- Python/ceval.c (revision 69603) +++ Python/ceval.c (working copy) @@ -1283,7 +1283,10 @@ case BINARY_MODULO: w = POP(); v = TOP(); - x = PyNumber_Remainder(v, w); + if (PyString_CheckExact(v)) + x = PyString_Format(v, w); + else + x = PyNumber_Remainder(v, w); Py_DECREF(v); Py_DECREF(w); SET_TOP(x); Index: Lib/test/test_opcodes.py =================================================================== --- Lib/test/test_opcodes.py (revision 69603) +++ Lib/test/test_opcodes.py (working copy) @@ -102,7 +102,13 @@ g = eval('lambda a=1: None') self.assertNotEquals(f, g) + def test_modulo_of_string_subclasses(self): + class MyString(str): + def __mod__(self, value): + return 42 + self.assertEqual(MyString() % 3, 42) + def test_main(): run_unittest(OpcodeTest)