[New-bugs-announce] [issue8977] Globalize lonely augmented assignment
Demur Rumed
report at bugs.python.org
Fri Jun 11 22:26:40 CEST 2010
New submission from Demur Rumed <junkmute at hotmail.com>:
A=[1,2,3]
def f(x):
A+=x,
This throws an error. The solution: state "global a". I find it odd that augmented assignment should be viewed the same as assignment in descerning local variables. This patch repairs such to maintain a as a variable of the global namespace
Some might find the following an issue
def f(x):
if x:
A+=4,
else:
A=[3]
print("f",x,A)
def g(x):
if not x:
A=[3]
else:
A+=4,
print("g",x,A)
In f, A is a global variable. In g, A is a local variable. Thus g(1) throws UnboundLocalError while f(1) appends 4 to A
----------
components: Interpreter Core
files: symtable.diff
keywords: patch
messages: 107581
nosy: serprex
priority: normal
severity: normal
status: open
title: Globalize lonely augmented assignment
type: feature request
versions: Python 3.1
Added file: http://bugs.python.org/file17633/symtable.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8977>
_______________________________________
More information about the New-bugs-announce
mailing list