8000 bpo-40334: Rename PyConfig.use_peg to _use_peg_parser (GH-19670) · python/cpython@1def775 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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:

Lib/test/test_flufl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import __future__
22
import unittest
33
import sys
4+
from test import support
45

56

6-
@unittest.skipIf(sys.flags.use_peg, "Not supported by pegen yet")
7+
@support.skip_if_new_parser("Not supported by pegen yet")
78
class FLUFLTests(unittest.TestCase):
89

910
def test_barry_as_bdfl(self):

Lib/test/test_fstring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import decimal
1313
import sys
1414
import unittest
15+
from test import support
1516

1617
a_global = 'global variable'
1718

@@ -206,7 +207,7 @@ def test_ast_line_numbers_nested(self):
206207
call = binop.right.values[1].value
207208
self.assertEqual(type(call), ast.Call)
208209
self.assertEqual(call.lineno, 3)
209-
if not sys.flags.use_peg:
210+
if support.use_old_parser():
210211
self.assertEqual(call.col_offset, 11)
211212

212213
def test_ast_line_numbers_duplicate_expression(self):

Lib/test/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ def test_deeply_nested_list(self):
900900
st = parser.expr(e)
901901
st.compile()
902902

903-
@unittest.skipIf(sys.flags.use_peg, "Pegen does not trigger memory error with this many parenthesis")
903+
@support.skip_if_new_parser("Pegen does not trigger memory error with this many parenthesis")
904904
def test_trigger_memory_error(self):
905905
e = self._nested_expression(100)
906906
rc, out, err = assert_python_failure('-Xoldparser', '-c', e)

Lib/test/test_peg_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import PurePath
77
from typing import Any, Union, Iterable, Tuple
88
from textwrap import dedent
9+
from test import support
910

1011

1112
TEST_CASES = [
@@ -720,7 +721,7 @@ def test_incorrect_ast_generation_with_specialized_errors(self) -> None:
720721
f"Actual error message does not match expexted for {source}"
721722
)
722723

723-
@unittest.skipIf(sys.flags.use_peg, "This tests nothing for now, since compile uses pegen as well")
724+
@support.skip_if_new_parser("This tests nothing for now, since compile uses pegen as well")
724725
@unittest.expectedFailure
725726
def test_correct_but_known_to_fail_ast_generation_on_source_files(self) -> None:
726727
for source in GOOD_BUT_FAIL_SOURCES:

Lib/test/test_positional_only_arg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest
66
import sys
77

8-
from test.support import check_syntax_error
8+
from test.support import check_syntax_error, use_old_parser
99

1010

1111
def global_pos_only_f(a, b, /):
@@ -24,7 +24,7 @@ def assertRaisesSyntaxError(self, codestr, regex="invalid syntax"):
2424
compile(codestr + "\n", "<test>", "single")
2525

2626
def test_invalid_syntax_errors(self):
27-
if not sys.flags.use_peg:
27+
if use_old_parser():
2828
check_syntax_error(self, "def f(a, b = 5, /, c): pass", "non-default argument follows default argument")
2929
check_syntax_error(self, "def f(a = 5, b, /, c): pass", "non-default argument follows default argument")
3030
check_syntax_error(self, "def f(a = 5, b=1, /, c, *, d=2): pass", "non-default argument follows default argument")
@@ -47,7 +47,7 @@ def test_invalid_syntax_errors(self):
4747
check_syntax_error(self, "def f(a, *, c, /, d, e): pass")
4848

4949
def test_invalid_syntax_errors_async(self):
50-
if not sys.flags.use_peg:
50+
if use_old_parser():
5151
check_syntax_error(self, "async def f(a, b = 5, /, c): pass", "non-default argument follows default argument")
5252
check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "non-default argument follows default argument")
5353
check_syntax_error(self, "async def f(a = 5, b=1, /, c, d=2): pass", "non-default argument follows default argument")
@@ -236,7 +236,7 @@ def test_lambdas(self):
236236
self.assertEqual(x(1, 2), 3)
237237

238238
def test_invalid_syntax_lambda(self):
239-
if not sys.flags.use_peg:
239+
if use_old_parser():
240240
check_syntax_error(self, "lambda a, b = 5, /, c: None", "non-default argument follows default argument")
241241
check_syntax_error(self, "lambda a = 5, b, /, c: None", "non-default argument follows default argument")
242242
check_syntax_error(self, "lambda a = 5, b, /: None", "non-default argument follows default argument")

Lib/test/test_string_literals.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import tempfile
3434
import unittest
3535
import warnings
36+
from test.support import check_syntax_warning, use_old_parser
3637

3738

3839
TEMPLATE = r"""# coding: %s
@@ -63,8 +64,6 @@ def byte(i):
6364

6465
class TestLiterals(unittest.TestCase):
6566

66-
from test.support import check_syntax_warning
67-
6867
def setUp(self):
6968
self.save_path = sys.path[:]
7069
self.tmpdir = tempfile.mkdtemp()
@@ -119,7 +118,7 @@ def test_eval_str_invalid_escape(self):
119118
eval("'''\n\\z'''")
120119
self.assertEqual(len(w), 1)
121120
self.assertEqual(w[0].filename, '<string>')
122-
if not sys.flags.use_peg:
121+
if use_old_parser():
123122
self.assertEqual(w[0].lineno, 1)
124123

125124
with warnings.catch_warnings(record=True) as w:
@@ -129,7 +128,7 @@ def test_eval_str_invalid_escape(self):
129128
exc = cm.exception
130129
self.assertEqual(w, [])
131130
self.assertEqual(exc.filename, '<string>')
132-
if not sys.flags.use_peg:
131+
if use_old_parser():
133132
self.assertEqual(exc.lineno, 1)
134133

135134
def test_eval_str_raw(self):
@@ -170,7 +169,7 @@ def test_eval_bytes_invalid_escape(self):
170169
eval("b'''\n\\z'''")
171170
self.assertEqual(len(w), 1)
172171
self.assertEqual(w[0].filename, '<string>')
173-
if not sys.flags.use_peg:
172+
if use_old_parser():
174173
self.assertEqual(w[0].lineno, 1)
175174

176175
with warnings.catch_warnings(record=True) as w:
@@ -180,7 +179,7 @@ def test_eval_bytes_invalid_escape(self):
180179
exc = cm.exception
181180
self.assertEqual(w, [])
182181
self.assertEqual(exc.filename, '<string>')
183-
if not sys.flags.use_peg:
182+
if use_old_parser():
184183
self.assertEqual(exc.lineno, 1)
185184

186185
def test_eval_bytes_raw(self):

Lib/test/test_syntax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ def _check_error(self, code, errtext,
678678
def test_assign_call(self):
679679
self._check_error("f() = 1", "assign")
680680

681-
@unittest.skipIf(sys.flags.use_peg, "Pegen does not produce a specialized error "
682-
"message yet")
681+
@support.skip_if_new_parser("Pegen does not produce a specialized error "
682+
"message yet")
683683
def test_assign_del(self):
684684
self._check_error("del f()", "delete")
685685

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def __hash__(self):
545545
def test_sys_flags(self):
546546
self.assertTrue(sys.flags)
547547
attrs = ("debug",
548-
"inspect", "interactive", "optimize", "use_peg",
548+
"inspect", "interactive", "optimize",
549549
"dont_write_bytecode", "no_user_site", "no_site",
550550
"ignore_environment", "verbose", "bytes_warning", "quiet",
551551
"hash_randomization", "isolated", "dev_mode", "utf8_mode")

Lib/test/test_traceback.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,7 @@ def outer_raise():
656656
self.assertIn('inner_raise() # Marker', blocks[2])
657657
self.check_zero_div(blocks[2])
658658

659-
@unittest.skipIf(sys.flags.use_peg,
660-
"Pegen is arguably better here, so no need to fix this")
659+
@support.skip_if_new_parser("Pegen is arguably better here, so no need to fix this")
661660
def test_syntax_error_offset_at_eol(self):
662661
# See #10186.
663662
def e():

Lib/test/test_type_comments.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ast
22
import sys
33
import unittest
4+
from test import support
45

56

67
funcdef = """\
@@ -218,7 +219,7 @@ def favk(
218219
"""
219220

220221

221-
@unittest.skipIf(sys.flags.use_peg, "Pegen does not support type comments yet")
222+
@support.skip_if_new_parser("Pegen does not support type comments yet")
222223
class TypeCommentTests(unittest.TestCase):
223224

224225
lowest = 4 # Lowest minor version supported

Lib/test/test_unparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_constant_tuples(self):
328328
ast.Constant(value=(1, 2, 3), kind=None), "(1, 2, 3)"
329329
)
330330

331-
@unittest.skipIf(sys.flags.use_peg, "Pegen does not support type annotation yet")
331+
@test.support.skip_if_new_parser("Pegen does not support type annotation yet")
332332
def test_function_type(self):
333333
for function_type in (
334334
"() -> int",

0 commit comments

Comments
 (0)
0