www.python.org/sf/738094 for i in range(N) optimization
The jury is still out on whether it is an elegant, brilliant patch or a horrendous hack.
Isn't this flawed in the case where it's called by a C function rather than directly from the bytecode VM? If the C function was called in the spot marked X below:
for ... in X(...): ...
(where X is the C function that calls range(), probably through some PyObject_Call() variation), then the check in the patch would trigger incorrectly.
--Guido van Rossum (home page: http://www.python.org/%7Eguido/)