[Python-bugs-list] [ python-Feature Requests-753600 ] why should += produce name binding?

SourceForge.net noreply@sourceforge.net
Thu, 12 Jun 2003 15:16:40 -0700


Feature Requests item #753600, was opened at 2003-06-12 18:16
Message generated for change (Tracker Item Submitted) made by Item Submitter
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.


















----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=753600&group_id=5470