starlark icon indicating copy to clipboard operation
starlark copied to clipboard

spec: allow parentheses on LHS of augmented assignment?

Open josharian opened this issue 7 years ago • 3 comments

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.

josharian avatar Nov 25 '18 17:11 josharian

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

laurentlb avatar Nov 26 '18 15:11 laurentlb

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.

josharian avatar Nov 30 '18 20:11 josharian