File tree 2 files changed +10
-11
lines changed
ruff_python_parser/src/parser
2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -2779,8 +2779,7 @@ l[(x:=1):-1]
2779
2779
test.py:6:5: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
2780
2780
test.py:7:5: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
2781
2781
test.py:10:3: SyntaxError: Unparenthesized named expression cannot be used here
2782
- test.py:10:3: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
2783
- Found 6 errors.
2782
+ Found 5 errors.
2784
2783
2785
2784
----- stderr -----
2786
2785
"
Original file line number Diff line number Diff line change @@ -874,16 +874,16 @@ impl<'src> Parser<'src> {
874
874
let lower =
875
875
self . parse_named_expression_or_higher ( ExpressionContext :: starred_conditional ( ) ) ;
876
876
877
- if self . options . target_version < PythonVersion :: PY310
878
- && lower. is_unparenthesized_named_expr ( )
879
- {
880
- self . add_unsupported_syntax_error (
881
- UnsupportedSyntaxErrorKind :: UnparWalrusBefore310 ,
882
- lower. range ( ) ,
883
- ) ;
884
- }
885
-
886
877
if self . at_ts ( NEWLINE_EOF_SET . union ( [ TokenKind :: Rsqb , TokenKind :: Comma ] . into ( ) ) ) {
878
+ // check this here because if we don't return, we will emit a ParseError instead
879
+ if self . options . target_version < PythonVersion :: PY310
880
+ && lower. is_unparenthesized_named_expr ( )
881
+ {
882
+ self . add_unsupported_syntax_error (
883
+ UnsupportedSyntaxErrorKind :: UnparWalrus ,
884
+ lower. range ( ) ,
885
+ ) ;
886
+ }
887
887
return lower. expr ;
888
888
}
889
889
You can’t perform that action at this time.
0 commit comments