Assert the parser is at augmented assign token (#10269)

## Summary

This PR updates fixes one of the `FIXME` comment to assert that the
parser is at one of the possible augmented assignment token when parsing
an augmented assignment statement.

## Test Plan

1. Add valid test cases for all the possible augmented assignment tokens
2. Add invalid test cases similar to assignment statement
This commit is contained in:
Dhruv Manilawala
2024-03-07 18:37:09 +05:30
committed by GitHub
parent b5cc384bb1
commit 035ac75fae
8 changed files with 2032 additions and 151 deletions

View File

@@ -27,17 +27,6 @@ await x = 42
a < b < c = 42
foo() = 42
# N.B. It looks like the parser can't generate a top-level
# FormattedValue, where as the official Python AST permits
# representing a single f-string containing just a variable as a
# FormattedValue directly.
#
# Bottom line is that because of this, this test is (at present)
# duplicative with the `fstring` test. That is, in theory these tests
# could fail independently, but in practice their failure or success
# is coupled.
#
# See: https://docs.python.org/3/library/ast.html#ast.FormattedValue
f"{quux}" = 42
f"{foo} and {bar}" = 42

View File

@@ -0,0 +1,34 @@
# This is similar to `./invalid_assignment_targets.py`, but for augmented
# assignment targets.
x or y += 42
(x := 5) += 42
x + y += 42
-x += 42
(lambda _: 1) += 42
a if b else c += 42
{"a": 5} += 42
{a} += 42
[x for x in xs] += 42
{x for x in xs} += 42
{x: x * 2 for x in xs} += 42
(x for x in xs) += 42
await x += 42
(yield x) += 42
(yield from xs) += 42
a < b < c += 42
foo() += 42
f"{quux}" += 42
f"{foo} and {bar}" += 42
"foo" += 42
b"foo" += 42
123 += 42
True += 42
None += 42
... += 42
*foo() += 42
[x, foo(), y] += [42, 42, 42]
[[a, b], [[42]], d] += [[1, 2], [[3]], 4]
(x, foo(), y) += (42, 42, 42)

View File

@@ -1,3 +1,18 @@
x += 1
x.y += (1, 2, 3)
x[y] += (1, 2, 3)
# All possible augmented assignment tokens
x += 1
x -= 1
x *= 1
x /= 1
x //= 1
x %= 1
x **= 1
x &= 1
x |= 1
x ^= 1
x <<= 1
x >>= 1
x @= 1