Skip to content

Commit 3782497

Browse files
authored
[3.9] bpo-40939: Fix test_keyword for the old parser (GH-20814)
1 parent dc40105 commit 3782497

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

Grammar/python.gram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ atom[expr_ty]:
477477
| 'True' { _Py_Constant(Py_True, NULL, EXTRA) }
478478
| 'False' { _Py_Constant(Py_False, NULL, EXTRA) }
479479
| 'None' { _Py_Constant(Py_None, NULL, EXTRA) }
480-
| '__new_parser__' { RAISE_SYNTAX_ERROR("You found it!") }
480+
| '__peg_parser__' { RAISE_SYNTAX_ERROR("You found it!") }
481481
| &STRING strings
482482
| NUMBER
483483
| &'(' (tuple | group | genexp)

Lib/keyword.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'False',
2020
'None',
2121
'True',
22-
'__new_parser__',
22+
'__peg_parser__',
2323
'and',
2424
'as',
2525
'assert',

Lib/pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ class Helper:
18171817
'False': '',
18181818
'None': '',
18191819
'True': '',
1820-
'__new_parser__': '',
1820+
'__peg_parser__': '',
18211821
'and': 'BOOLEAN',
18221822
'as': 'with',
18231823
'assert': ('assert', ''),

Lib/test/test_keyword.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import keyword
22
import unittest
3+
from test.support import use_old_parser
34

45

56
class Test_iskeyword(unittest.TestCase):
@@ -21,7 +22,10 @@ def test_changing_the_kwlist_does_not_affect_iskeyword(self):
2122
self.assertFalse(keyword.iskeyword('eggs'))
2223

2324
def test_all_keywords_fail_to_be_used_as_names(self):
24-
for key in keyword.kwlist:
25+
all_keywords = set(keyword.kwlist)
26+
if use_old_parser():
27+
all_keywords.discard('__peg_parser__')
28+
for key in all_keywords:
2529
with self.assertRaises(SyntaxError):
2630
exec(f"{key} = 42")
2731

Parser/pegen/parse.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static KeywordToken *reserved_keywords[] = {
7171
NULL,
7272
NULL,
7373
(KeywordToken[]) {
74-
{"__new_parser__", 530},
74+
{"__peg_parser__", 530},
7575
{NULL, -1},
7676
},
7777
};
@@ -10567,7 +10567,7 @@ slice_rule(Parser *p)
1056710567
// | 'True'
1056810568
// | 'False'
1056910569
// | 'None'
10570-
// | '__new_parser__'
10570+
// | '__peg_parser__'
1057110571
// | &STRING strings
1057210572
// | NUMBER
1057310573
// | &'(' (tuple | group | genexp)
@@ -10711,18 +10711,18 @@ atom_rule(Parser *p)
1071110711
D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ',
1071210712
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'None'"));
1071310713
}
10714-
{ // '__new_parser__'
10714+
{ // '__peg_parser__'
1071510715
if (p->error_indicator) {
1071610716
D(p->level--);
1071710717
return NULL;
1071810718
}
10719-
D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'__new_parser__'"));
10719+
D(fprintf(stderr, "%*c> atom[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'__peg_parser__'"));
1072010720
Token * _keyword;
1072110721
if (
10722-
(_keyword = _PyPegen_expect_token(p, 530)) // token='__new_parser__'
10722+
(_keyword = _PyPegen_expect_token(p, 530)) // token='__peg_parser__'
1072310723
)
1072410724
{
10725-
D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'__new_parser__'"));
10725+
D(fprintf(stderr, "%*c+ atom[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'__peg_parser__'"));
1072610726
_res = RAISE_SYNTAX_ERROR ( "You found it!" );
1072710727
if (_res == NULL && PyErr_Occurred()) {
1072810728
p->error_indicator = 1;
@@ -10733,7 +10733,7 @@ atom_rule(Parser *p)
1073310733
}
1073410734
p->mark = _mark;
1073510735
D(fprintf(stderr, "%*c%s atom[%d-%d]: %s failed!\n", p->level, ' ',
10736-
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'__new_parser__'"));
10736+
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'__peg_parser__'"));
1073710737
}
1073810738
{ // &STRING strings
1073910739
if (p->error_indicator) {

0 commit comments

Comments
 (0)