[New-bugs-announce] [issue21904] Multiple closures accessing the same non-local variable always see the same value
report at bugs.python.org
Wed Jul 2 13:54:10 CEST 2014
New submission from Steve Holden:
When repeated use of a nonlocal variable is made (e.g. to define multiple functions in a loop) ideally the closure should reflect the value of the local variable at the time of use. This should at least be explicitly documented if the behavior is considered not to be a bug.
The code sample attached shows that the closures produced operate differently inside and outside the enclosing function.
Without an explicit nonlocal declaration the closure should not be able to affect the nonlocal variable's value (which anyway hardly makes sense once the enclosing namespace has been destroyed), so I think it's possible to argue that this behavior is a bug, but I'd value comments from experienced developers.
keywords: needs review
title: Multiple closures accessing the same non-local variable always see the same value
versions: Python 2.7, Python 3.3
Added file: http://bugs.python.org/file35829/bugreport.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce