This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author benrg
Recipients ashwch, benrg, docs@python, ezio.melotti, r.david.murray
Date 2013-01-24.05:18:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1359004722.06.0.51526932482.issue16701@psf.upfronthosting.co.za>
In-reply-to
Content
> As far as I know Ezio is correct, "when possible" means "when the target is mutable".  The documentation should probably be clarified on that point.

Yes, it needs to be made very, very clear in the documentation. As I said, I'm not aware of any other language in which var op= expr does not mean the same thing as var = var op expr. I'm actually amazed that neither of you recognize the weirdness of this behavior (and even more amazed that GvR apparently didn't). I'm an experienced professional programmer, and I dutifully read the official documentation cover to cover when I started programming in Python, and I interpreted this paragraph wrongly, because I interpreted it in the only way that made sense given the meaning of these operators in every other language that has them. Python is designed to be unsurprising; constructs generally mean what it looks like they mean. You need to explain this unique feature of Python in terms so clear that it can't possibly be mistaken for the behavior of all of the other languages.

> Remember, Python names refer to pointers to objects, they are not variables in the sense that other languages have variables.

That has nothing to do with this. Yes, in Python (and Java and Javascript and many other languages) all objects live on the heap, local variables are not first-class objects, and var = expr is a special form. That doesn't change the fact that in all of those other languages, var += expr means var = var + expr. In C++ local variables are first-class objects and var += expr means var.operator+=(expr) or operator+=(var, expr), and this normally modifies the thing on the left in a way that's visible through references. But in C++, var = var + expr also modifies the thing on the left, in the same way.

In Python and Java and Javascript and ..., var = value never visibly mutates any heap object, and neither does var = var + value (in any library that defines a sane + operator), and therefore neither should var += value (again, in any sanely designed library). And it doesn't. Except in Python.
History
Date User Action Args
2013-01-24 05:18:42benrgsetrecipients: + benrg, ezio.melotti, r.david.murray, docs@python, ashwch
2013-01-24 05:18:42benrgsetmessageid: <1359004722.06.0.51526932482.issue16701@psf.upfronthosting.co.za>
2013-01-24 05:18:42benrglinkissue16701 messages
2013-01-24 05:18:41benrgcreate