summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-06-11 18:29:13 (GMT)
committerGitHub <noreply@github.com>2020-06-11 18:29:13 (GMT)
commit3782497cc22e70b41e32ac09cb06d3948074d8a7 (patch)
tree7d785de2fb0f083d1dffe828604096d5bdc50291
parentdc40105c88b968a50c3458e10e1d732e957ef0a3 (diff)
downloadcpython-3782497cc22e70b41e32ac09cb06d3948074d8a7.zip
cpython-3782497cc22e70b41e32ac09cb06d3948074d8a7.tar.gz
cpython-3782497cc22e70b41e32ac09cb06d3948074d8a7.tar.bz2
[3.9] bpo-40939: Fix test_keyword for the old parser (GH-20814)
-rw-r--r--Grammar/python.gram2
-rw-r--r--Lib/keyword.py2
-rwxr-xr-xLib/pydoc.py2
-rw-r--r--Lib/test/test_keyword.py6
-rw-r--r--Parser/pegen/parse.c14
5 files changed, 15 insertions, 11 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 2c350ef..1510683 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -477,7 +477,7 @@ atom[expr_ty]:
| 'True' { _Py_Constant(Py_True, NULL, EXTRA) }
| 'False' { _Py_Constant(Py_False, NULL, EXTRA) }
| 'None' { _Py_Constant(Py_None, NULL, EXTRA) }
- | '__new_parser__' { RAISE_SYNTAX_ERROR("You found it!") }
+ | '__peg_parser__' { RAISE_SYNTAX_ERROR("You found it!") }
| &STRING strings
| NUMBER
| &'(' (tuple | group | genexp)
diff --git a/Lib/keyword.py b/Lib/keyword.py
index afc3db3..a4db67e 100644
--- a/Lib/keyword.py
+++ b/Lib/keyword.py
@@ -19,7 +19,7 @@ kwlist = [
'False',
'None',
'True',
- '__new_parser__',
+ '__peg_parser__',
'and',
'as',
'assert',
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index a5368bf..35ef3eb 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1817,7 +1817,7 @@ class Helper:
'False': '',
'None': '',
'True': '',
- '__new_parser__': '',
+ '__peg_parser__': '',
'and': 'BOOLEAN',
'as': 'with',
'assert': ('assert', ''),
diff --git a/Lib/test/test_keyword.py b/Lib/test/test_keyword.py
index 3e2a8b3..e1042cf 100644
--- a/Lib/test/test_keyword.py
+++ b/Lib/test/test_keyword.py
@@ -1,5 +1,6 @@
import keyword
import unittest
+from test.support import use_old_parser
class Test_iskeyword(unittest.TestCase):
@@ -21,7 +22,10 @@ class Test_iskeyword(unittest.TestCase):
self.assertFalse(keyword.iskeyword('eggs'))
def test_all_keywords_fail_to_be_used_as_names(self):
- for key in keyword.kwlist:
+ all_keywords = set(keyword.kwlist)
+ if use_old_parser():
+ all_keywords.discard('__peg_parser__')
+ for key in all_keywords:
with self.assertRaises(SyntaxError):
exec(f"{key} = 42")
diff --git a/Parser/pegen/parse.c b/Parser/pegen/parse.c
index 4f13bf7..d43ebb9 100644
--- a/Parser/pegen/parse.c
+++ b/Parser/pegen/parse.c
@@ -71,7 +71,7 @@ static KeywordToken *reserved_keywords[] = {
NULL,
NULL,
(KeywordToken[]) {
- {"__new_parser__", 530},
+ {"__peg_parser__", 530},
{NULL, -1},
},
};
@@ -10567,7 +10567,7 @@ slice_rule(Parser *p)
// | 'True'
// | 'False'
// | 'None'
-// | '__new_parser__'
+// | '__peg_parser__'
// | &STRING strings
// | NUMBER
// | &'(' (tuple | group | genexp)
@@ -10711,18 +10711,18 @@ atom_rule(Parser *p)
D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'None'"));
}
- { // '__new_parser__'
+ { // '__peg_parser__'
if (p->error_indicator) {
D(p->level--);
return NULL;
}
- D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'__new_parser__'"));
+ D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'__peg_parser__'"));
Token * _keyword;
if (
- (_keyword = _PyPegen_expect_token(p, 530)) // token='__new_parser__'
+ (_keyword = _PyPegen_expect_token(p, 530)) // token='__peg_parser__'
)
{
- D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'__new_parser__'"));
+ D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'__peg_parser__'"));
_res = RAISE_SYNTAX_ERROR ( "You found it!" );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
@@ -10733,7 +10733,7 @@ atom_rule(Parser *p)
}
p->mark = _mark;
D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ',
- p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'__new_parser__'"));
+ p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'__peg_parser__'"));
}
{ // &STRING strings
if (p->error_indicator) {