Skip to content

Commit eb63c6e

Browse files
committed
fix duplicate syntax error
1 parent c6b21ca commit eb63c6e

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

crates/ruff/tests/lint.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2779,8 +2779,7 @@ l[(x:=1):-1]
27792779
test.py:6:5: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
27802780
test.py:7:5: SyntaxError: Cannot use unparenthesized assignment expression on Python 3.9 (syntax was added in Python 3.10)
27812781
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.
27842783
27852784
----- stderr -----
27862785
"

crates/ruff_python_parser/src/parser/expression.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -874,16 +874,16 @@ impl<'src> Parser<'src> {
874874
let lower =
875875
self.parse_named_expression_or_higher(ExpressionContext::starred_conditional());
876876

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-
886877
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+
}
887887
return lower.expr;
888888
}
889889

0 commit comments

Comments
 (0)