Hi, On Wed, Jun 07, 2006 at 02:07:48AM +0200, Thomas Wouters wrote: > I just submitted http://python.org/sf/1501934 and assigned it to Neal so it > doesn't get forgotten before 2.5 goes out ;) It seems Python 2.5 compiles > the following code incorrectly:
No, no, it's an underground move by Jeremy to allow assignment to variables of enclosing scopes: [in 2.5] def f(): x = 5 def g(): x += 1 g() print x # 6 The next move is to say that this is an expected feature of the augmented assignment operators, from which it follows naturally that we need a pseudo-augmented assignment that doesn't actually read the old value: [in 2.6] def f(): x = 5 def g(): x := 6 g() print x # 6 Credits to Samuele's evil side for the ideas. His non-evil side doesn't agree, and neither does mine, of course :-) More seriously, a function with a variable that is only written to as the target of augmented assignments cannot possibly be something else than a newcomer's mistake: the augmented assignments will always raise UnboundLocalError. Maybe this should be a SyntaxWarning? A bientot, Armin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com