Relax Syntax for Augmented Arithmetic?

Terry Reedy tjreedy at udel.edu
Sun Jan 18 15:11:46 EST 2009


andrew cooke wrote:
> Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data
> model#object.__iadd__
> 
> Just a suggestion I thought I'd throw out...  There's a restriction in
> the language implementation on exactly what can go the left of an
> augmented arithmetic expression.
> 
> For example:
>>>> a = 3
>>>> a **= 2
> 
> is ok, but:
>>>> class Foo():
> ...   def __init__():
> ...     self.a = 3
> ...   def __ipow__(self, x):
> ...     self.a **= x
> ...
>>>> Foo() **= 2

Calls return objects and therefore cannot be the target of an 
assignment, augmented or otherwise.  The target of an assignment is a 
name or collection slot, both of which are grammatical constructs, not 
objects.




More information about the Python-list mailing list