Index: Python/ceval.c =================================================================== --- Python/ceval.c (revision 66053) +++ Python/ceval.c (working copy) @@ -2095,7 +2095,16 @@ case FOR_ITER: /* before: [iter]; after: [iter, iter()] *or* [] */ v = TOP(); - x = (*v->ob_type->tp_iternext)(v); + if (v->ob_type->tp_iternext != NULL) + x = (*v->ob_type->tp_iternext)(v); + else { + PyErr_Format(PyExc_TypeError, + "%.200s is no longer an iterator", + v->ob_type->tp_name); + err = -1; + break; + } + if (x != NULL) { PUSH(x); PREDICT(STORE_FAST); Index: Lib/test/test_iter.py =================================================================== --- Lib/test/test_iter.py (revision 66053) +++ Lib/test/test_iter.py (working copy) @@ -853,7 +853,22 @@ self.assertEqual(list(b), list(zip(range(5), range(5)))) self.assertEqual(list(b), []) + def test_3720(self): + # Avoid a crash, when an iterator deletes its __next__() method. + class BadIterator(object): + def __iter__(self): + return self + def __next__(self): + del BadIterator.__next__ + return 1 + try: + for i in BadIterator() : + pass + except TypeError: + pass + + def test_main(): run_unittest(TestCase)