Skip to content

Commit b46d091

Browse files
committed
add note on 3.8 and 3.9 compatibility when using := syntax
1 parent 9139759 commit b46d091

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

doc/macros.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,17 @@ Bindings are established using standard assignment expression syntax, `name := v
134134

135135
The old `unpythonic` env-assignment syntax, `name << value`, is also supported for backward compatibility. This was the preferred syntax in v0.15.0 to v0.15.2.
136136

137-
**CAUTION**: All let-bindings must be established in the bindings subform. If you absolutely need to do establish more bindings in the body, see the sequencing construct `do[]` and its syntax `local[x := 42]`.
137+
**NOTE**: All let-bindings must be established in the bindings subform. If you absolutely need to do establish more bindings in the body, see the sequencing construct `do[]` and its syntax `local[x := 42]`.
138+
139+
**NOTE**: Language support for using an assignment expression inside a subscript *without parenthesizing it* was [added in Python 3.10](https://docs.python.org/3/whatsnew/3.10.html#other-language-changes). The syntax accepted when running on Python 3.8 or 3.9 is:
140+
141+
```python
142+
let[(x := 17),
143+
(y := 23)][
144+
print(x, y)]
145+
```
146+
147+
That is, Python 3.8 and 3.9 require parentheses around each let binding if you use the new `:=` syntax, because syntactically, the bindings subform looks like a subscript. The unit tests use this syntax so that they work on 3.8 and 3.9. But for new code using Python 3.10 or later, it is preferable to omit the parentheses to improve readability.
138148

139149
The same syntax for the bindings subform is used by:
140150

0 commit comments

Comments
 (0)