diff options
author | Angus Gratton <angus@redyak.com.au> | 2025-04-01 12:09:41 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-04-07 15:43:03 +1000 |
commit | 57f1e60dd05a58b6d78c72af31ee4d706b1c47a1 (patch) | |
tree | eb2fdd378cdd1debab3348aa37e9c59b5418aec7 /tests/cpydiff/syntax_assign_expr.py | |
parent | e34412f0f49032fcd3a08317c8f2e01c7bdae24f (diff) |
tests/cpydiff: Update CPy diff for assign expr in nested comprehensions.
Since 7c1584aef1 MicroPython matches CPython in most cases, aside from
nested comprehensions.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'tests/cpydiff/syntax_assign_expr.py')
-rw-r--r-- | tests/cpydiff/syntax_assign_expr.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/cpydiff/syntax_assign_expr.py b/tests/cpydiff/syntax_assign_expr.py index 58f57ca1f..704c5c3ec 100644 --- a/tests/cpydiff/syntax_assign_expr.py +++ b/tests/cpydiff/syntax_assign_expr.py @@ -1,8 +1,8 @@ """ categories: Syntax,Operators -description: MicroPython allows using := to assign to the variable of a comprehension, CPython raises a SyntaxError. -cause: MicroPython is optimised for code size and doesn't check this case. -workaround: Do not rely on this behaviour if writing CPython compatible code. +description: MicroPython allows := to assign to the iteration variable in nested comprehensions, CPython does not. +cause: MicroPython is optimised for code size. Although it is a syntax error to assign to the iteration variable in a standard comprehension (same as CPython), it doesn't check if an inner nested comprehension assigns to the iteration variable of the outer comprehension. +workaround: Do not use := to assign to the iteration variable of a comprehension. """ -print([i := -1 for i in range(4)]) +print([[(j := i) for i in range(2)] for j in range(2)]) |