[Python-bugs-list] [ python-Feature Requests-753600 ] why should += produce name binding?
SourceForge.net
noreply@sourceforge.net
Sat, 14 Jun 2003 09:24:43 -0700
Feature Requests item #753600, was opened at 2003-06-13 00:16
Message generated for change (Comment added) made by loewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=753600&group_id=5470
Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Gregory Smith (gregsmith)
Assigned to: Nobody/Anonymous (nobody)
Summary: why should += produce name binding?
Initial Comment:
Currently, in
def x():
foo += 1
... 'foo' is a local variable. Why should it be?
If the semantics are changed so that augmented
assignment is not a name-binding operation,
then only broken code will be affected.
This would allow you to use simple things
like 'EventCount += 1' without having to
use 'global EventCount'. After all, I can do
'EventList.append(...)' without the global decl.
For another (better) example, see
http://mail.python.org/pipermail/edu-sig/2001-June/001329.html
In the response to the above, the poster is referred
to PEP227 which lists 'assignment' as a name-binding
operation. There is no clear-cut implication that this
includes augmented assignment, and in the Python
ref manual, one can only infer this behaviour from
the statement that x += y is almost equivalent
to x = x+y, which is pretty weak. In any case, since
an augmented assignment to a name always requires the
a-priori existence of that name in
an accessible namespace, IMHO it should not
produce a binding.
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2003-06-14 18:24
Message:
Logged In: YES
user_id=21627
Can you please explain, in detail, what semantics you
propose for += if the variable does not refer to a mutable
object?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=753600&group_id=5470