Skip to content

Commit 1def775

Browse files
authored
bpo-40334: Rename PyConfig.use_peg to _use_peg_parser (GH-19670)
* Rename PyConfig.use_peg to _use_peg_parser * Document PyConfig._use_peg_parser and mark it a deprecated * Mark -X oldparser option and PYTHONOLDPARSER env var as deprecated in the documentation. * Add use_old_parser() and skip_if_new_parser() to test.support * Remove sys.flags.use_peg: use_old_parser() uses _testinternalcapi.get_configs() instead. * Enhance test_embed tests * subprocess._args_from_interpreter_flags() copies -X oldparser
1 parent a25f3c4 commit 1def775

26 files changed

+83
-54
lines changed

Doc/c-api/init_config.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,16 @@ PyConfig
686686
687687
:data:`sys._xoptions`.
688688
689+
.. c:member:: int _use_peg_parser
690+
691+
Enable PEG parser? Default: 1.
692+
693+
Set to 0 by :option:`-X oldparser <-X>` and :envvar:`PYTHONOLDPARSER`.
694+
695+
See also :pep:`617`.
696+
697+
.. deprecated-removed:: 3.9 3.10
698+
689699
If ``parse_argv`` is non-zero, ``argv`` arguments are parsed the same
690700
way the regular Python parses command line arguments, and Python
691701
arguments are stripped from ``argv``: see :ref:`Command Line Arguments

Doc/using/cmdline.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ Miscellaneous options
427427

428428
* ``-X faulthandler`` to enable :mod:`faulthandler`;
429429
* ``-X oldparser``: enable the traditional LL(1) parser. See also
430-
:envvar:`PYTHONOLDPARSER`.
430+
:envvar:`PYTHONOLDPARSER` and :pep:`617`.
431431
* ``-X showrefcount`` to output the total reference count and number of used
432432
memory blocks when the program finishes or after each statement in the
433433
interactive interpreter. This only works on debug builds.
@@ -480,6 +480,9 @@ Miscellaneous options
480480

481481
The ``-X showalloccount`` option has been removed.
482482

483+
.. deprecated-removed:: 3.9 3.10
484+
The ``-X oldparser`` option.
485+
483486

484487
Options you shouldn't use
485488
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -578,8 +581,11 @@ conflict.
578581

579582
.. envvar:: PYTHONOLDPARSER
580583

581-
If this is set it is equivalent to specifying the :option:`-X`
582-
``oldparser`` option.
584+
If this is set to a non-empty string, enable the traditional LL(1) parser.
585+
586+
See also the :option:`-X` ``oldparser`` option and :pep:`617`.
587+
588+
.. deprecated-removed:: 3.9 3.10
583589

584590

585591
.. envvar:: PYTHONINSPECT

Include/cpython/initconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ typedef struct {
149149

150150
/* Enable PEG parser?
151151
1 by default, set to 0 by -X oldparser and PYTHONOLDPARSER */
152-
int use_peg;
152+
int _use_peg_parser;
153153

154154
/* Enable tracemalloc?
155155
Set by -X tracemalloc=N and PYTHONTRACEMALLOC. -1 means unset */

Lib/subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _args_from_interpreter_flags():
326326
if dev_mode:
327327
args.extend(('-X', 'dev'))
328328
for opt in ('faulthandler', 'tracemalloc', 'importtime',
329-
'showrefcount', 'utf8'):
329+
'showrefcount', 'utf8', 'oldparser'):
330330
if opt in xoptions:
331331
value = xoptions[opt]
332332
if value is True:

Lib/test/support/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,3 +3454,13 @@ def wait_process(pid, *, exitcode, timeout=None):
34543454
# sanity check: it should not fail in practice
34553455
if pid2 != pid:
34563456
raise AssertionError(f"pid {pid2} != pid {pid}")
3457+
3458+
3459+
def use_old_parser():
3460+
import _testinternalcapi
3461+
config = _testinternalcapi.get_configs()
3462+
return (config['config']['_use_peg_parser'] == 0)
3463+
3464+
3465+
def skip_if_new_parser(msg):
3466+
return unittest.skipIf(not use_old_parser(), msg)

Lib/test/test_codeop.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"""
55
import sys
66
import unittest
7-
from test.support import is_jython
7+
from test import support
88

99
from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
1010
import io
1111

12-
if is_jython:
12+
if support.is_jython:
1313

1414
def unify_callables(d):
1515
for n,v in d.items():
@@ -21,7 +21,7 @@ class CodeopTests(unittest.TestCase):
2121

2222
def assertValid(self, str, symbol='single'):
2323
'''succeed iff str is a valid piece of code'''
24-
if is_jython:
24+
if support.is_jython:
2525
code = compile_command(str, "<input>", symbol)
2626
self.assertTrue(code)
2727
if symbol == "single":
@@ -60,7 +60,7 @@ def test_valid(self):
6060
av = self.assertValid
6161

6262
# special case
63-
if not is_jython:
63+
if not support.is_jython:
6464
self.assertEqual(compile_command(""),
6565
compile("pass", "<input>", 'single',
6666
PyCF_DONT_IMPLY_DEDENT))
@@ -122,7 +122,7 @@ def test_valid(self):
122122
av("def f():\n pass\n#foo\n")
123123
av("@a.b.c\ndef f():\n pass\n")
124124

125-
@unittest.skipIf(sys.flags.use_peg, "Pegen does not support PyCF_DONT_INPLY_DEDENT yet")
125+
@support.skip_if_new_parser("Pegen does not support PyCF_DONT_INPLY_DEDENT yet")
126126
def test_incomplete(self):
127127
ai = self.assertIncomplete
128128

Lib/test/test_compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def test_single_statement(self):
501501
self.compile_single("if x:\n f(x)\nelse:\n g(x)")
502502
self.compile_single("class T:\n pass")
503503

504-
@unittest.skipIf(sys.flags.use_peg, 'Pegen does not disallow multiline single stmts')
504+
@support.skip_if_new_parser('Pegen does not disallow multiline single stmts')
505505
def test_bad_single_statement(self):
506506
self.assertInvalidSingle('1\n2')
507507
self.assertInvalidSingle('def f(): pass')

Lib/test/test_embed.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
347347
'isolated': 0,
348348
'use_environment': 1,
349349
'dev_mode': 0,
350-
'use_peg': 1,
350+
'_use_peg_parser': 1,
351351

352352
'install_signal_handlers': 1,
353353
'use_hash_seed': 0,
@@ -729,7 +729,7 @@ def test_init_from_config(self):
729729
'import_time': 1,
730730
'show_ref_count': 1,
731731
'malloc_stats': 1,
732-
'use_peg': 0,
732+
'_use_peg_parser': 0,
733733

734734
'stdio_encoding': 'iso8859-1',
735735
'stdio_errors': 'replace',
@@ -792,6 +792,7 @@ def test_init_compat_env(self):
792792
'user_site_directory': 0,
793793
'faulthandler': 1,
794794
'warnoptions': ['EnvVar'],
795+
'_use_peg_parser': 0,
795796
}
796797
self.check_all_configs("test_init_compat_env", config, preconfig,
797798
api=API_COMPAT)
@@ -819,6 +820,7 @@ def test_init_python_env(self):
819820
'user_site_directory': 0,
820821
'faulthandler': 1,
821822
'warnoptions': ['EnvVar'],
823+
'_use_peg_parser': 0,
822824
}
823825
self.check_all_configs("test_init_python_env", config, preconfig,
824826
api=API_PYTHON)

Lib/test/test_eof.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_EOFS(self):
2626
else:
2727
raise support.TestFailed
2828

29-
@unittest.skipIf(sys.flags.use_peg, "TODO for PEG -- fails with new parser")
29+
@support.skip_if_new_parser("TODO for PEG -- fails with new parser")
3030
def test_line_continuation_EOF(self):
3131
"""A continuation at the end of input must be an error; bpo2180."""
3232
expect = 'unexpected EOF while parsing (<string>, line 1)'

Lib/test/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def ckmsg(src, msg, exception=SyntaxError):
178178
s = '''if True:\n print()\n\texec "mixed tabs and spaces"'''
179179
ckmsg(s, "inconsistent use of tabs and spaces in indentation", TabError)
180180

181-
@unittest.skipIf(sys.flags.use_peg, "Pegen column offsets might be different")
181+
@support.skip_if_new_parser("Pegen column offsets might be different")
182182
def testSyntaxErrorOffset(self):
183183
def check(src, lineno, offset, encoding='utf-8'):
184184
with self.assertRaises(SyntaxError) as cm:

0 commit comments

Comments
 (0)