[Python-Dev] SyntaxError: can't assign to function call

Neal Becker ndbecker2 at gmail.com
Wed Aug 9 18:35:13 CEST 2006

class X (object):

X() += 2

> SyntaxError: can't assign to function call

Suppose I actually had defined __iadd__ for class X.  Python says this
syntax is invalid.  I wish is wasn't.

Here's where I might use it.  Suppose I have a container class.  Suppose I
could make a slice of this container, like so:

c = Container()
s = Slice (c, 0, 10)

where "Slice" is a class.  Then:

s += 2

Would perform iadd on the slice of the container.  A convenient syntax would

Slice (c, 0, 10) += 2

Does anyone else think this would be a good addition to Python?

More information about the Python-Dev mailing list