[3.9] bpo-40939: Fix test_keyword for the old parser (GH-20814)
This commit is contained in:
parent
dc40105c88
commit
3782497cc2
|
@ -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)
|
||||
|
|
|
@ -19,7 +19,7 @@ kwlist = [
|
|||
'False',
|
||||
'None',
|
||||
'True',
|
||||
'__new_parser__',
|
||||
'__peg_parser__',
|
||||
'and',
|
||||
'as',
|
||||
'assert',
|
||||
|
|
|
@ -1817,7 +1817,7 @@ class Helper:
|
|||
'False': '',
|
||||
'None': '',
|
||||
'True': '',
|
||||
'__new_parser__': '',
|
||||
'__peg_parser__': '',
|
||||
'and': 'BOOLEAN',
|
||||
'as': 'with',
|
||||
'assert': ('assert', ''),
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue