Skip to content

bpo-40939: Remove the old parser #20768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -695,16 +695,6 @@ PyConfig

:data:`sys._xoptions`.

.. c:member:: int _use_peg_parser

Enable PEG parser? Default: 1.

Set to 0 by :option:`-X oldparser <-X>` and :envvar:`PYTHONOLDPARSER`.

See also :pep:`617`.

.. deprecated-removed:: 3.9 3.10

If ``parse_argv`` is non-zero, ``argv`` arguments are parsed the same
way the regular Python parses command line arguments, and Python
arguments are stripped from ``argv``: see :ref:`Command Line Arguments
Expand Down
11 changes: 0 additions & 11 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,6 @@ Miscellaneous options
defines the following possible values:

* ``-X faulthandler`` to enable :mod:`faulthandler`;
* ``-X oldparser``: enable the traditional LL(1) parser. See also
:envvar:`PYTHONOLDPARSER` and :pep:`617`.
* ``-X showrefcount`` to output the total reference count and number of used
memory blocks when the program finishes or after each statement in the
interactive interpreter. This only works on debug builds.
Expand Down Expand Up @@ -587,15 +585,6 @@ conflict.
:option:`-d` multiple times.


.. envvar:: PYTHONOLDPARSER

If this is set to a non-empty string, enable the traditional LL(1) parser.

See also the :option:`-X` ``oldparser`` option and :pep:`617`.

.. deprecated-removed:: 3.9 3.10


.. envvar:: PYTHONINSPECT

If this is set to a non-empty string it is equivalent to specifying the
Expand Down
4 changes: 0 additions & 4 deletions Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ typedef struct {
Set to 1 by -X faulthandler and PYTHONFAULTHANDLER. -1 means unset. */
int faulthandler;

/* Enable PEG parser?
1 by default, set to 0 by -X oldparser and PYTHONOLDPARSER */
int _use_peg_parser;

/* Enable tracemalloc?
Set by -X tracemalloc=N and PYTHONTRACEMALLOC. -1 means unset */
int tracemalloc;
Expand Down
2 changes: 1 addition & 1 deletion Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _args_from_interpreter_flags():
if dev_mode:
args.extend(('-X', 'dev'))
for opt in ('faulthandler', 'tracemalloc', 'importtime',
'showrefcount', 'utf8', 'oldparser'):
'showrefcount', 'utf8'):
if opt in xoptions:
value = xoptions[opt]
if value is True:
Expand Down
10 changes: 0 additions & 10 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,13 +1993,3 @@ def wait_process(pid, *, exitcode, timeout=None):
# sanity check: it should not fail in practice
if pid2 != pid:
raise AssertionError(f"pid {pid2} != pid {pid}")


def use_old_parser():
import _testinternalcapi
config = _testinternalcapi.get_configs()
return (config['config']['_use_peg_parser'] == 0)


def skip_if_new_parser(msg):
return unittest.skipIf(not use_old_parser(), msg)
4 changes: 0 additions & 4 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'isolated': 0,
'use_environment': 1,
'dev_mode': 0,
'_use_peg_parser': 1,

'install_signal_handlers': 1,
'use_hash_seed': 0,
Expand Down Expand Up @@ -733,7 +732,6 @@ def test_init_from_config(self):
'import_time': 1,
'show_ref_count': 1,
'malloc_stats': 1,
'_use_peg_parser': 0,

'stdio_encoding': 'iso8859-1',
'stdio_errors': 'replace',
Expand Down Expand Up @@ -807,7 +805,6 @@ def test_init_compat_env(self):
'warnoptions': ['EnvVar'],
'platlibdir': 'env_platlibdir',
'module_search_paths': self.IGNORE_CONFIG,
'_use_peg_parser': 0,
}
self.check_all_configs("test_init_compat_env", config, preconfig,
api=API_COMPAT)
Expand Down Expand Up @@ -837,7 +834,6 @@ def test_init_python_env(self):
'warnoptions': ['EnvVar'],
'platlibdir': 'env_platlibdir',
'module_search_paths': self.IGNORE_CONFIG,
'_use_peg_parser': 0,
}
self.check_all_configs("test_init_python_env", config, preconfig,
api=API_PYTHON)
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ def baz():
check('def f():\n x, y: int', 2, 3)
check('[*x for x in xs]', 1, 2)
check('foo(x for x in range(10), 100)', 1, 5)
check('(yield i) = 2', 1, 1 if support.use_old_parser() else 2)
check('def f(*):\n pass', 1, 7 if support.use_old_parser() else 8)
check('for 1 in []: pass', 1, 5 if support.use_old_parser() else 7)
check('(yield i) = 2', 1, 2)
check('def f(*):\n pass', 1, 8)
check('for 1 in []: pass', 1, 7)

@cpython_only
def testSettingException(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_flufl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_barry_as_bdfl(self):
self.assertTrue(cm.exception.lineno, 2)
# The old parser reports the end of the token and the new
# parser reports the start of the token
self.assertEqual(cm.exception.offset, 4 if support.use_old_parser() else 3)
self.assertEqual(cm.exception.offset, 3)

def test_guido_as_bdfl(self):
code = '2 {0} 3'
Expand All @@ -33,7 +33,7 @@ def test_guido_as_bdfl(self):
self.assertEqual(cm.exception.lineno, 1)
# The old parser reports the end of the token and the new
# parser reports the start of the token
self.assertEqual(cm.exception.offset, 4 if support.use_old_parser() else 3)
self.assertEqual(cm.exception.offset, 3)


if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import types
import decimal
import unittest
from test.support import temp_cwd, use_old_parser
from test.support import temp_cwd
from test.support.script_helper import assert_python_failure

a_global = 'global variable'
Expand Down Expand Up @@ -1049,7 +1049,6 @@ def test_errors(self):
r"f'{1000:j}'",
])

@unittest.skipIf(use_old_parser(), "The old parser only supports <fstring> as the filename")
def test_filename_in_syntaxerror(self):
# see issue 38964
with temp_cwd() as cwd:
Expand Down
110 changes: 47 additions & 63 deletions Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Python test set -- part 1, grammar.
# This just tests whether the parser accepts them all.

from test.support import check_syntax_error, check_syntax_warning, use_old_parser
from test.support import check_syntax_error, check_syntax_warning
import inspect
import unittest
import sys
Expand Down Expand Up @@ -1714,69 +1714,53 @@ def __exit__(self, *args):
with manager() as x, manager():
pass

if not use_old_parser():
test_cases = [
"""if 1:
with (
manager()
):
pass
""",
"""if 1:
with (
manager() as x
):
pass
""",
"""if 1:
with (
manager() as (x, y),
manager() as z,
):
pass
""",
"""if 1:
with (
manager(),
manager()
):
pass
""",
"""if 1:
with (
manager() as x,
manager() as y
):
pass
""",
"""if 1:
with (
manager() as x,
manager()
):
pass
""",
"""if 1:
with (
manager() as x,
manager() as y,
manager() as z,
):
pass
""",
"""if 1:
with (
manager() as x,
manager() as y,
manager(),
):
pass
""",
]
for case in test_cases:
with self.subTest(case=case):
compile(case, "<string>", "exec")
with (
manager()
):
pass

with (
manager() as x
):
pass

with (
manager() as (x, y),
manager() as z,
):
pass

with (
manager(),
manager()
):
pass

with (
manager() as x,
manager() as y
):
pass

with (
manager() as x,
manager()
):
pass

with (
manager() as x,
manager() as y,
manager() as z,
):
pass

with (
manager() as x,
manager() as y,
manager(),
):
pass

def test_if_else_expr(self):
# Test ifelse expressions in various cases
Expand Down
Loading