Skip to content

Commit 0fda0cd

Browse files
committed
address review points, remove tests and update news entry
1 parent b0cad50 commit 0fda0cd

4 files changed

Lines changed: 210 additions & 233 deletions

File tree

Grammar/python.gram

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,6 @@ compare_op_bitwise_or_pair[CmpopExprPair*]:
805805
| invalid_eqeqeq
806806

807807
eq_bitwise_or[CmpopExprPair*]: '==' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, Eq, a) }
808-
invalid_eqeqeq:
809-
| a='==' b='=' {
810-
_PyPegen_tokens_are_adjacent(a, b)
811-
? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant 'is' instead of '==='?")
812-
: NULL
813-
}
814808
noteq_bitwise_or[CmpopExprPair*]:
815809
| (tok='!=' { _PyPegen_check_barry_as_flufl(p, tok) ? NULL : tok}) a=bitwise_or {_PyPegen_cmpop_expr_pair(p, NotEq, a) }
816810
lte_bitwise_or[CmpopExprPair*]: '<=' a=bitwise_or { _PyPegen_cmpop_expr_pair(p, LtE, a) }
@@ -1682,3 +1676,10 @@ invalid_bitwise_or:
16821676
? RAISE_SYNTAX_ERROR_KNOWN_RANGE(b, c, "invalid syntax. Maybe you meant 'or' or '|' instead of '||'?")
16831677
: NULL
16841678
}
1679+
1680+
invalid_eqeqeq:
1681+
| a='==' b='=' {
1682+
_PyPegen_tokens_are_adjacent(a, b)
1683+
? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' instead of '==='?")
1684+
: NULL
1685+
}

Lib/test/test_syntax.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,37 +3631,13 @@ def test_double_ampersand(self):
36313631
lineno=2,
36323632
end_lineno=2,
36333633
offset=5,
3634-
)
3635-
3636-
def test_diamond_operator(self):
3637-
self._check_error(
3638-
"1<>2",
3639-
"invalid syntax",
3640-
lineno=1,
3641-
end_lineno=1,
3642-
offset=2,
3643-
end_offset=4,
3644-
)
3645-
3646-
def test_diamond_operator_barry_as_flufl(self):
3647-
# Under barry_as_FLUFL, '<>' is the valid "not equal" operator
3648-
compile(
3649-
"from __future__ import barry_as_FLUFL\n1<>2",
3650-
"<test>", "exec",
3651-
)
3652-
self._check_error(
3653-
"from __future__ import barry_as_FLUFL\na < > b",
3654-
"invalid syntax",
3655-
lineno=2,
3656-
end_lineno=2,
3657-
offset=5,
36583634
end_offset=6,
36593635
)
36603636

36613637
def test_triple_equal(self):
36623638
self._check_error(
36633639
"a === b",
3664-
r"Maybe you meant 'is' instead of '==='\?",
3640+
r"Maybe you meant '==' instead of '==='\?",
36653641
lineno=1,
36663642
end_lineno=1,
36673643
offset=3,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Improve :exc:`SyntaxError` messages for common operator typos coming from other languages: ``=<``, ``=>``, and ``=!`` now suggest ``<=``, ``>=``, and ``!=`` respectively, ``===`` suggests ``is``, and ``<>`` shows a tailored message suggesting ``!=``.
1+
Improve :exc:`SyntaxError` messages for common operator typos coming from other languages: ``=<``, ``=>``, and ``=!`` now suggest ``<=``, ``>=``, and ``!=`` respectively, and ``===`` suggests ``==``.

0 commit comments

Comments
 (0)