Skip to content

Commit 65cf172

Browse files
committed
add question mark in the suggestion and tests
1 parent 9472172 commit 65cf172

3 files changed

Lines changed: 48 additions & 8 deletions

File tree

Grammar/python.gram

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ compare_op_bitwise_or_pair[CmpopExprPair*]:
805805

806806
eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) }
807807
invalid_eqeqeq:
808-
| a='==' b='=' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' instead of '==='") }
808+
| a='==' b='=' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' instead of '==='?") }
809809
noteq_bitwise_or[CmpopExprPair*]:
810810
| (tok='!=' { _PyPegen_check_barry_as_flufl(p, tok) ? NULL : tok}) a=bitwise_or {_PyPegen_cmpop_expr_pair(p, NotEq, a) }
811811
lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) }
@@ -1316,9 +1316,9 @@ invalid_assignment:
13161316
"'%s' is an illegal expression for augmented assignment",
13171317
_PyPegen_get_expr_name(a)
13181318
)}
1319-
| star_expressions a='=' b='<' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '<=' instead of '=<'") }
1320-
| star_expressions a='=' b='>' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '>=' instead of '=>'") }
1321-
| star_expressions a='=' b='!' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '!=' instead of '=!'") }
1319+
| star_expressions a='=' b='<' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '<=' instead of '=<'?") }
1320+
| star_expressions a='=' b='>' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '>=' instead of '=>'?") }
1321+
| star_expressions a='=' b='!' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '!=' instead of '=!'?") }
13221322
invalid_ann_assign_target[expr_ty]:
13231323
| list
13241324
| tuple

Lib/test/test_syntax.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,46 @@ def test_ifexp_body_stmt_else_stmt(self):
35053505
]:
35063506
self._check_error(f"x = {lhs_stmt} if 1 else {rhs_stmt}", msg)
35073507

3508+
def test_triple_equal(self):
3509+
self._check_error(
3510+
"a === b",
3511+
"Maybe you meant '==' instead of '==='",
3512+
lineno=1,
3513+
end_lineno=1,
3514+
offset=3,
3515+
end_offset=6,
3516+
)
3517+
3518+
def test_eq_lt_typo(self):
3519+
self._check_error(
3520+
"a =< b",
3521+
"Maybe you meant '<=' instead of '=<'",
3522+
lineno=1,
3523+
end_lineno=1,
3524+
offset=3,
3525+
end_offset=5,
3526+
)
3527+
3528+
def test_eq_gt_typo(self):
3529+
self._check_error(
3530+
"a => b",
3531+
"Maybe you meant '>=' instead of '=>'",
3532+
lineno=1,
3533+
end_lineno=1,
3534+
offset=3,
3535+
end_offset=5,
3536+
)
3537+
3538+
def test_eq_bang_typo(self):
3539+
self._check_error(
3540+
"a =! b",
3541+
"Maybe you meant '!=' instead of '=!'",
3542+
lineno=1,
3543+
end_lineno=1,
3544+
offset=3,
3545+
end_offset=5,
3546+
)
3547+
35083548

35093549
class LazyImportRestrictionTestCase(SyntaxErrorTestCase):
35103550
"""Test syntax restrictions for lazy imports."""

Parser/parser.c

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)