Skip to content

Commit 57f1e60

Browse files
projectgusdpgeorge
authored andcommitted
tests/cpydiff: Update CPy diff for assign expr in nested comprehensions.
Since 7c1584a MicroPython matches CPython in most cases, aside from nested comprehensions. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent e34412f commit 57f1e60

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
categories: Syntax,Operators
3-
description: MicroPython allows using := to assign to the variable of a comprehension, CPython raises a SyntaxError.
4-
cause: MicroPython is optimised for code size and doesn't check this case.
5-
workaround: Do not rely on this behaviour if writing CPython compatible code.
3+
description: MicroPython allows := to assign to the iteration variable in nested comprehensions, CPython does not.
4+
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.
5+
workaround: Do not use := to assign to the iteration variable of a comprehension.
66
"""
77

8-
print([i := -1 for i in range(4)])
8+
print([[(j := i) for i in range(2)] for j in range(2)])

0 commit comments

Comments
 (0)