]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-40939: Fix test_keyword for the old parser (GH-20814)
authorPablo Galindo <Pablogsal@gmail.com>
Thu, 11 Jun 2020 18:29:13 +0000 (19:29 +0100)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2020 18:29:13 +0000 (19:29 +0100)
Grammar/python.gram
Lib/keyword.py
Lib/pydoc.py
Lib/test/test_keyword.py
Parser/pegen/parse.c

index 2c350ef68a214e0af0f9d9eb3b0507dd5acc6224..1510683d888ebe5324d243d1609f682707f66414 100644 (file)
@@ -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)
index afc3db3942ccbc15317e5f940089d5080d28b68c..a4db67e5597c6ef1af65762196c75d36bcb3e7f9 100644 (file)
@@ -19,7 +19,7 @@ kwlist = [
     'False',
     'None',
     'True',
-    '__new_parser__',
+    '__peg_parser__',
     'and',
     'as',
     'assert',
index a5368bf8bfe551b09d1c513c39427235858e0cba..35ef3ebdc688e61277125a587aeafb7c347a6756 100755 (executable)
@@ -1817,7 +1817,7 @@ class Helper:
         'False': '',
         'None': '',
         'True': '',
-        '__new_parser__': '',
+        '__peg_parser__': '',
         'and': 'BOOLEAN',
         'as': 'with',
         'assert': ('assert', ''),
index 3e2a8b3fb7f4c3bfd1948f5278593545e81226c4..e1042cf18217c3bb91dc7a27981f0c6ffc3bc0e8 100644 (file)
@@ -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")
 
index 4f13bf772f261a29996226e6d318be82e882cf2d..d43ebb9e6c286fe128dd8cd735ad52b18176fa50 100644 (file)
@@ -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) {