On Mon, Nov 17, 2014 at 9:40 AM, Guido van Rossum guido@python.org wrote:
I don't want to contemplate a new __next__ protocol. The existing protocol was carefully designed and tuned to have minimal memory overhead (even to the point where the exception instance returned may be reused). Wapping each result would just result in an extra allocation + deallocation per iteration, unless you can play games with reference counts or do something else to complicate the semantics). Introducing __nextx__ would require thousands of libraries implementing this to incur churn as they feel the pressure to switch to the new protocol, and the compatibility issue would be felt everywhere.
This sounds totally reasonable to me.
The problem we're trying to fix is unique to generators (thereby also implicating generator expressions).
I suppose since you're only fixing generators, then that is literally the only problem you are trying to fix, but it is more general than that. I have encountered this sort of problem writing __next__ by hand in Python -- that is, that bugs inside code I call result in silent control flow changes rather than a visible exception.
-- Devin