@@ -38,12 +38,16 @@ def validate(lst):
3838 if type (k ) is not Name :
3939 return False # pragma: no cover, only reached if the test fails.
4040 return True
41+ # Python 3.8 and Python 3.9 require the parens around the walrus when used inside a subscript.
42+ # TODO: Remove the parens (in all walrus-inside-subscript instances in this file) when we bump minimum Python to 3.10.
43+ # From https://docs.python.org/3/whatsnew/3.10.html:
44+ # Assignment expressions can now be used unparenthesized within set literals and set comprehensions, as well as in sequence indexes (but not slices).
4145 test [validate (the [canonize_bindings (q [k0 , v0 ].elts )])] # noqa: F821, it's quoted.
4246 test [validate (the [canonize_bindings (q [((k0 , v0 ),)].elts )])] # noqa: F821
4347 test [validate (the [canonize_bindings (q [(k0 , v0 ), (k1 , v1 )].elts )])] # noqa: F821
44- test [validate (the [canonize_bindings ([q [k0 := v0 ]])])] # noqa: F821, it's quoted.
48+ test [validate (the [canonize_bindings ([q [( k0 := v0 ) ]])])] # noqa: F821, it's quoted.
4549 test [validate (the [canonize_bindings ([q [k0 << v0 ]])])] # noqa: F821, it's quoted.
46- test [validate (the [canonize_bindings (q [k0 := v0 , k1 := v1 ].elts )])] # noqa: F821, it's quoted.
50+ test [validate (the [canonize_bindings (q [( k0 := v0 ), ( k1 := v1 ) ].elts )])] # noqa: F821, it's quoted.
4751 test [validate (the [canonize_bindings (q [k0 << v0 , k1 << v1 ].elts )])] # noqa: F821, it's quoted.
4852
4953 # --------------------------------------------------------------------------------
@@ -53,17 +57,17 @@ def validate(lst):
5357 # need this utility, so we must test it first.
5458 with testset ("isenvassign" ):
5559 test [not isenvassign (q [x ])] # noqa: F821
56- test [isenvassign (q [x := 42 ])] # noqa: F821
60+ test [isenvassign (q [( x := 42 ) ])] # noqa: F821
5761 test [isenvassign (q [x << 42 ])] # noqa: F821
5862
5963 with testset ("islet" ):
6064 test [not islet (q [x ])] # noqa: F821
6165 test [not islet (q [f ()])] # noqa: F821
6266
6367 # unpythonic 0.15.3+, Python 3.8+
64- test [islet (the [expandrq [let [x := 21 ][2 * x ]]]) == ("expanded_expr" , "let" )] # noqa: F821, `let` defines `x`
68+ test [islet (the [expandrq [let [( x := 21 ) ][2 * x ]]]) == ("expanded_expr" , "let" )] # noqa: F821, `let` defines `x`
6569 test [islet (the [expandrq [let [[x := 21 ] in 2 * x ]]]) == ("expanded_expr" , "let" )] # noqa: F821
66- test [islet (the [expandrq [let [2 * x , where [x := 21 ]]]]) == ("expanded_expr" , "let" )] # noqa: F821
70+ test [islet (the [expandrq [let [2 * x , where [( x := 21 ) ]]]]) == ("expanded_expr" , "let" )] # noqa: F821
6771
6872 # unpythonic 0.15.0 to 0.15.2, previous modern notation for bindings
6973 test [islet (the [expandrq [let [x << 21 ][2 * x ]]]) == ("expanded_expr" , "let" )] # noqa: F821, `let` defines `x`
@@ -96,7 +100,7 @@ def f2():
96100 return 2 * x # noqa: F821
97101 test [islet (the [testdata [0 ].decorator_list [0 ]]) == ("expanded_decorator" , "let" )]
98102
99- testdata = q [let [x := 21 ][2 * x ]] # noqa: F821
103+ testdata = q [let [( x := 21 ) ][2 * x ]] # noqa: F821
100104 test [islet (the [testdata ], expanded = False ) == ("lispy_expr" , "let" )]
101105
102106 testdata = q [let [x << 21 ][2 * x ]] # noqa: F821
@@ -196,7 +200,7 @@ def f5():
196200 test [not isdo (q [f ()])] # noqa: F821
197201
198202 # unpythonic 0.15.3+, Python 3.8+
199- test [isdo (the [expandrq [do [x := 21 , # noqa: F821
203+ test [isdo (the [expandrq [do [( x := 21 ) , # noqa: F821
200204 2 * x ]]]) == "expanded" ] # noqa: F821
201205
202206 test [isdo (the [expandrq [do [x << 21 , # noqa: F821
@@ -210,16 +214,16 @@ def f5():
210214 test [isdo (the [thedo ]) == "curried" ]
211215
212216 # unpythonic 0.15.3+, Python 3.8+
213- testdata = q [do [x := 21 , # noqa: F821
217+ testdata = q [do [( x := 21 ) , # noqa: F821
214218 2 * x ]] # noqa: F821
215219 test [isdo (the [testdata ], expanded = False ) == "do" ]
216220
217221 testdata = q [do0 [23 , # noqa: F821
218- x := 21 , # noqa: F821
222+ ( x := 21 ) , # noqa: F821
219223 2 * x ]] # noqa: F821
220224 test [isdo (the [testdata ], expanded = False ) == "do0" ]
221225
222- testdata = q [someothermacro [x := 21 , # noqa: F821
226+ testdata = q [someothermacro [( x := 21 ) , # noqa: F821
223227 2 * x ]] # noqa: F821
224228 test [not isdo (the [testdata ], expanded = False )]
225229
@@ -241,7 +245,7 @@ def f5():
241245 # Destructuring - envassign
242246
243247 with testset ("envassign destructuring (new env-assign syntax v0.15.3+)" ):
244- testdata = q [x := 42 ] # noqa: F821
248+ testdata = q [( x := 42 ) ] # noqa: F821
245249 view = UnexpandedEnvAssignView (testdata )
246250
247251 # read
@@ -316,7 +320,7 @@ def testletdestructuring(testdata):
316320 test [unparse (view .body ) == "(z * t)" ]
317321
318322 # lispy expr
319- testdata = q [let [x := 21 , y := 2 ][y * x ]] # noqa: F821
323+ testdata = q [let [( x := 21 ), ( y := 2 ) ][y * x ]] # noqa: F821
320324 testletdestructuring (testdata )
321325 testdata = q [let [x << 21 , y << 2 ][y * x ]] # noqa: F821
322326 testletdestructuring (testdata )
@@ -374,7 +378,7 @@ def testletdestructuring(testdata):
374378 testletdestructuring (testdata )
375379
376380 # disembodied haskelly let-where (just the content, no macro invocation)
377- testdata = q [y * x , where [x := 21 , y := 2 ]] # noqa: F821
381+ testdata = q [y * x , where [( x := 21 ), ( y := 2 ) ]] # noqa: F821
378382 testletdestructuring (testdata )
379383 testdata = q [y * x , where [x << 21 , y << 2 ]] # noqa: F821
380384 testletdestructuring (testdata )
@@ -599,7 +603,7 @@ def f8():
599603 # Destructuring - unexpanded do
600604
601605 with testset ("do destructuring (unexpanded) (new env-assign syntax v0.15.3+)" ):
602- testdata = q [do [local [x := 21 ], # noqa: F821
606+ testdata = q [do [local [( x := 21 ) ], # noqa: F821
603607 2 * x ]] # noqa: F821
604608 view = UnexpandedDoView (testdata )
605609 # read
@@ -611,11 +615,11 @@ def f8():
611615 test [isenvassign (the [thing ])]
612616 # write
613617 # This mutates the original, but we have to assign `view.body` to trigger the setter.
614- thebody [0 ] = q [local [x := 9001 ]] # noqa: F821
618+ thebody [0 ] = q [local [( x := 9001 ) ]] # noqa: F821
615619 view .body = thebody
616620
617621 # implicit do, a.k.a. extra bracket syntax
618- testdata = q [let [[local [x := 21 ], # noqa: F821
622+ testdata = q [let [[local [( x := 21 ) ], # noqa: F821
619623 2 * x ]]] # noqa: F821
620624 if sys .version_info >= (3 , 9 , 0 ): # Python 3.9+: the Index wrapper is gone.
621625 theimplicitdo = testdata .slice
@@ -630,7 +634,7 @@ def f8():
630634 thing = thebody [0 ].slice .value
631635 test [isenvassign (the [thing ])]
632636 # write
633- thebody [0 ] = q [local [x := 9001 ]] # noqa: F821
637+ thebody [0 ] = q [local [( x := 9001 ) ]] # noqa: F821
634638 view .body = thebody
635639
636640 test_raises [TypeError ,
0 commit comments