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.
This commit is contained in:
Lysandros Nikolaou 2020-04-30 01:53:30 +03:00 • committed by GitHub
parent 360371f79c
commit 69e802ed81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View file

@ -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;
}