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.

----------
files: bugreport.py
keywords: needs review
messages: 222094
nosy: holdenweb
priority: normal
severity: normal
status: open
title: Multiple closures accessing the same non-local variable always see the 
same value
type: behavior
versions: Python 2.7, Python 3.3
Added file: http://bugs.python.org/file35829/bugreport.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21904>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to