[Python-ideas] Globalize lonely augmented assignment
Éric Araujo
merwok at netwok.org
Fri Jun 11 23:37:45 CEST 2010
Hello list
I’m really uncomfortable with your proposal too. FTR, let me copy it:
You want this code to work:
A = [1, 2, 3]
def f(x):
A += [x]
f(4) # appends 4 to A
It fails today to be consistent with this equivalent code:
def f(x):
B = A + [x]
A = B
I can’t see one way working but not the other.
> To note, his counter example would currently raise an
> UnboundLocalError
It’s not an alternate example that would work today, but a consequence
of your proposal that we definitely don’t want (mutating immutable objects).
To add a third reason to reject your patch:
f = A.append # :)
Regards
More information about the Python-ideas
mailing list