Relax Syntax for Augmented Arithmetic?
andrew at acooke.org
Sun Jan 18 11:56:55 CET 2009
Context - http://docs.python.org/3.0/reference/datamodel.html?highlight=data
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.
>>> a = 3
>>> a **= 2
is ok, but:
>>> class Foo():
... def __init__():
... self.a = 3
... def __ipow__(self, x):
... self.a **= x
>>> Foo() **= 2
File "<stdin>", line 1
SyntaxError: illegal expression for augmented assignment
Now unless I've done something stupid above (always a possibility :o)
the implementation seems a bit strict (is it really a *syntax* error?
- I am not sure exactly what the restriction is).
This may seems like a small issue, but operators can really help with
making embedded DSLs in Python - they give quite a bit of "wiggle
room" to invent a syntax that is compact and intuitive. The
restriction above cuts into that (OK, so it's still a small
More information about the Python-list