Skip to content

Commit

Permalink
bpo-33645: Fix an "unknown parsing error" in the parser. (GH-7119)
Browse files Browse the repository at this point in the history
It is reproduced when parse the "<>" operator and run
Python with both options -3 and -We.
  • Loading branch information
serhiy-storchaka committed May 31, 2018
1 parent 9994eff commit d5e7556
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
check_py3k_warnings
import unittest
import sys
import warnings
# testing import *
from sys import *

Expand Down Expand Up @@ -628,7 +629,6 @@ def check(code, warntext):
with check_py3k_warnings((warntext, DeprecationWarning)):
compile(code, '<test string>', 'exec')
if sys.py3kwarning:
import warnings
with warnings.catch_warnings():
warnings.filterwarnings('error', category=DeprecationWarning)
with self.assertRaises(SyntaxError) as cm:
Expand Down Expand Up @@ -883,6 +883,13 @@ def test_comparison(self):
with check_py3k_warnings(('<> not supported in 3.x; use !=',
DeprecationWarning)):
if eval('1 < 1 > 1 == 1 >= 1 <= 1 <> 1 != 1 in 1 not in 1 is 1 is not 1'): pass
if sys.py3kwarning:
with warnings.catch_warnings():
warnings.filterwarnings('error', category=DeprecationWarning)
with self.assertRaises(DeprecationWarning) as cm:
compile('1 <> 1', '<test string>', 'eval')
self.assertIn('<> not supported in 3.x; use !=',
str(cm.exception))

def test_binary_mask_ops(self):
x = 1 & 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an "unknown parsing error" on parsing the "<>" operator when run
Python with both options ``-3`` and ``-We``.
2 changes: 2 additions & 0 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,8 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
"<> not supported in 3.x; use !=",
tok->filename, tok->lineno,
NULL, NULL)) {
tok->done = E_ERROR;
tok->cur = tok->inp;
return ERRORTOKEN;
}
}
Expand Down

0 comments on commit d5e7556

Please sign in to comment.