Skip to content

Commit f039f43

Browse files
committed
improve syntaxerror message <> typo
1 parent 30e8188 commit f039f43

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

Grammar/python.gram

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,11 @@ compare_op_bitwise_or_pair[CmpopExprPair*]:
805805
| invalid_eqeqeq
806806

807807
invalid_diamond_op:
808-
| a='<' b='>' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '!=' instead of '<>'?") }
808+
| a='<' b='>' {
809+
(p->flags & PyPARSE_BARRY_AS_BDFL)
810+
? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '<>' instead of '< >'?")
811+
: RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '!=' instead of '<>'?")
812+
}
809813
eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) }
810814
invalid_eqeqeq:
811815
| a='==' b='=' { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' instead of '==='?") }

Lib/test/test_syntax.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,6 +3515,16 @@ def test_diamond_operator(self):
35153515
end_offset=6,
35163516
)
35173517

3518+
def test_diamond_operator_barry_as_flufl(self):
3519+
self._check_error(
3520+
"from __future__ import barry_as_FLUFL\n1 < > 2",
3521+
"Maybe you meant '<>' instead of '< >'",
3522+
lineno=2,
3523+
end_lineno=2,
3524+
offset=3,
3525+
end_offset=6,
3526+
)
3527+
35183528
def test_triple_equal(self):
35193529
self._check_error(
35203530
"a === b",

Parser/parser.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)