@@ -2667,6 +2667,69 @@ fn walrus_before_py38() {
2667
2667
) ;
2668
2668
}
2669
2669
2670
+ #[ test]
2671
+ fn unparenthesized_walrus_before_py310 ( ) {
2672
+ let stdin = r#"
2673
+ # okay on 3.10 but not on 3.9
2674
+ {x := 1, 2, 3} # set literal
2675
+ {last := x for x in range(3)} # set comprehension
2676
+ # sequence indexes
2677
+ lst[x := 1]
2678
+ dct[x := 1]
2679
+
2680
+ # never okay
2681
+ l[x:=1:-1]
2682
+
2683
+ # always okay
2684
+ {(x := 1), 2, 3}
2685
+ {(last := x) for x in range(3)}
2686
+ lst[(x := 1)]
2687
+ dct[(x := 1)]
2688
+ l[(x:=1):-1]
2689
+ "# ;
2690
+
2691
+ // 1 error from "never okay" slice
2692
+ assert_cmd_snapshot ! ( Command :: new( get_cargo_bin( BIN_NAME ) )
2693
+ . args( STDIN_BASE_OPTIONS )
2694
+ . args( [ "--stdin-filename" , "test.py" ] )
2695
+ . arg( "--target-version=py310" )
2696
+ . arg( "-" )
2697
+ . pass_stdin( stdin) ,
2698
+ @r"
2699
+ success: false
2700
+ exit_code: 1
2701
+ ----- stdout -----
2702
+ test.py:10:3: SyntaxError: Unparenthesized named expression cannot be used here
2703
+ Found 1 error.
2704
+
2705
+ ----- stderr -----
2706
+ "
2707
+ ) ;
2708
+
2709
+ // 5 errors on 3.9 with preview - 4 from 3.9, 1 from above
2710
+ assert_cmd_snapshot ! ( Command :: new( get_cargo_bin( BIN_NAME ) )
2711
+ . args( STDIN_BASE_OPTIONS )
2712
+ . args( [ "--stdin-filename" , "test.py" ] )
2713
+ . arg( "--target-version=py39" )
2714
+ . arg( "--preview" )
2715
+ . arg( "-" )
2716
+ . pass_stdin( stdin) ,
2717
+ @r"
2718
+ success: false
2719
+ exit_code: 1
2720
+ ----- stdout -----
2721
+ test.py:3:2: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
2722
+ test.py:4:2: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
2723
+ test.py:6:5: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
2724
+ test.py:7:5: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
2725
+ test.py:10:3: SyntaxError: Unparenthesized named expression cannot be used here
2726
+ Found 5 errors.
2727
+
2728
+ ----- stderr -----
2729
+ "
2730
+ ) ;
2731
+ }
2732
+
2670
2733
#[ test]
2671
2734
fn match_before_py310 ( ) {
2672
2735
// ok on 3.10
0 commit comments