This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients Christopher.King, benjamin.peterson, bogklug, r.david.murray
Date 2013-02-26.20:38:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1361911122.96.0.572187413197.issue7423@psf.upfronthosting.co.za>
In-reply-to
Content
I hear what you are saying, but the "generalization" does not mean that they work exactly the same way.  The whole point of generators is that execution is lazy, which is what leads to the difference in behavior.  

The generator function *is* closed over the free variables.  That's what leads to the difference in behavior: the generator uses the value the free variable has when the generator executes.  I don't believe there is any practical way to implement what you are suggesting, even if we wanted to...which we would not be, since it would constitute a backward incompatible change in behavior.

Note also that this behavior of closures is not unique to Python.  See for example http://www.javascriptkit.com/javatutors/closures2.shtml.
History
Date User Action Args
2013-02-26 20:38:42r.david.murraysetrecipients: + r.david.murray, benjamin.peterson, bogklug, Christopher.King
2013-02-26 20:38:42r.david.murraysetmessageid: <1361911122.96.0.572187413197.issue7423@psf.upfronthosting.co.za>
2013-02-26 20:38:42r.david.murraylinkissue7423 messages
2013-02-26 20:38:42r.david.murraycreate