starlark
starlark copied to clipboard
spec: allow parentheses on LHS of augmented assignment?
Consider:
a = 1
(a) += 2
Python 2 and 3 both accept this, yielding a == 3.
Starlark rejects it. The spec (over in the Go implementation repo) says of augmented assignments: "The left-hand side must be a simple target: a name, an index expression, or a dot expression."
Should Starlark accept this code, to better match Python?
I originally filed this at https://github.com/google/starlark-go/issues/25, in response to the Go implementation panicking when evaluating this code.
Good catch!
The Go implementation doesn't seem very consistent:
(a) = 5 # okay
(a) += 1 # fails
Both statements are allowed by the Java implementation (used in Bazel).
I suspect it's a bug introduced by my change (https://github.com/google/starlark-go/commit/28ceca7fdc8d88c4b6a4a64453b2251e00f73f56).
I suggest that:
- We allow both statements
- We clarify the spec
The Go implementation now accepts both statements, so the only thing left here is the spec change. I’ll leave that for Alan or Laurent.