[Python-Dev] [PEP] += on return of function call result
Greg Ewing
greg@cosc.canterbury.ac.nz
Thu, 03 Apr 2003 15:04:27 +1200 (NZST)
Andrew Koenig <ark@research.att.com>:
> So the behavior of
>
> foo = d.setdefault(r,'')
> foo += "test %d\n" % t
>
> depends on what type foo has, and the OP didn't say.
I assumed that the code snippet was from his actual application, in
which case he *did* want it to work on strings, in which case, even if
he had the feature he wanted, it wouldn't have helped him.
I think the fact that this would only work when the value was mutable
is a good reason to disallow it. Too big a source of surprises,
otherwise.
Being forced to find another way to update the value in this case is a
feature, because the absence of such a way when the value is immutable
makes it clear that there's no way to do what you're trying to do!
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg@cosc.canterbury.ac.nz +--------------------------------------+