summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-04-29 22:53:30 (GMT)
committerGitHub <noreply@github.com>2020-04-29 22:53:30 (GMT)
commit69e802ed812e38cb68a4ab74af64b4f719b6cc78 (patch)
tree1c05825a7f7ee032471c4cdc8bb60c648b1f491e /Modules
parent360371f79c48f15bbcee7aeecacf97a899913b25 (diff)
downloadcpython-69e802ed812e38cb68a4ab74af64b4f719b6cc78.zip
cpython-69e802ed812e38cb68a4ab74af64b4f719b6cc78.tar.gz
cpython-69e802ed812e38cb68a4ab74af64b4f719b6cc78.tar.bz2
bpo-40334: Fix test_peg_parser to actually use the old parser (GH-19778)
Now that the default parser is the new PEG parser, ast.parse uses it, which means that we don't actually test something in test_peg_parser. This commit introduces a new keyword argument (`oldparser`) for `_peg_parser.parse_string` for specifying that a string needs to be parsed with the old parser. This keyword argument is used in the tests to actually compare the ASTs the new parser generates with those generated by the old parser.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_peg_parser.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Modules/_peg_parser.c b/Modules/_peg_parser.c
index e1ec36e..59b80f9 100644
--- a/Modules/_peg_parser.c
+++ b/Modules/_peg_parser.c
@@ -45,11 +45,13 @@ error:
PyObject *
_Py_parse_string(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *keywords[] = {"string", "mode", NULL};
+ static char *keywords[] = {"string", "mode", "oldparser", NULL};
char *the_string;
char *mode_str = "exec";
+ int oldparser = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s", keywords, &the_string, &mode_str)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|sp", keywords,
+ &the_string, &mode_str, &oldparser)) {
return NULL;
}
@@ -77,7 +79,13 @@ _Py_parse_string(PyObject *self, PyObject *args, PyObject *kwds)
PyCompilerFlags flags = _PyCompilerFlags_INIT;
flags.cf_flags = PyCF_IGNORE_COOKIE;
- mod_ty res = PyPegen_ASTFromString(the_string, mode, &flags, arena);
+ mod_ty res;
+ if (oldparser) {
+ res = PyParser_ASTFromString(the_string, "<string>", mode, &flags, arena);
+ }
+ else {
+ res = PyPegen_ASTFromString(the_string, mode, &flags, arena);
+ }
if (res == NULL) {
goto error;
}