Skip to content

Commit d5e7556

Browse files
bpo-33645: Fix an "unknown parsing error" in the parser. (GH-7119)
It is reproduced when parse the "<>" operator and run Python with both options -3 and -We.
1 parent 9994eff commit d5e7556

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/test/test_grammar.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
check_py3k_warnings
66
import unittest
77
import sys
8+
import warnings
89
# testing import *
910
from sys import *
1011

@@ -628,7 +629,6 @@ def check(code, warntext):
628629
with check_py3k_warnings((warntext, DeprecationWarning)):
629630
compile(code, '<test string>', 'exec')
630631
if sys.py3kwarning:
631-
import warnings
632632
with warnings.catch_warnings():
633633
warnings.filterwarnings('error', category=DeprecationWarning)
634634
with self.assertRaises(SyntaxError) as cm:
@@ -883,6 +883,13 @@ def test_comparison(self):
883883
with check_py3k_warnings(('<> not supported in 3.x; use !=',
884884
DeprecationWarning)):
885885
if eval('1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1'): pass
886+
if sys.py3kwarning:
887+
with warnings.catch_warnings():
888+
warnings.filterwarnings('error', category=DeprecationWarning)
889+
with self.assertRaises(DeprecationWarning) as cm:
890+
compile('1 <> 1', '<test string>', 'eval')
891+
self.assertIn('<> not supported in 3.x; use !=',
892+
str(cm.exception))
886893

887894
def test_binary_mask_ops(self):
888895
x = 1 & 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed an "unknown parsing error" on parsing the "<>" operator when run
2+
Python with both options ``-3`` and ``-We``.

Parser/tokenizer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,8 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
16361636
"<> not supported in 3.x; use !=",
16371637
tok->filename, tok->lineno,
16381638
NULL, NULL)) {
1639+
tok->done = E_ERROR;
1640+
tok->cur = tok->inp;
16391641
return ERRORTOKEN;
16401642
}
16411643
}

0 commit comments

Comments
 (0)