| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a25f3c4 commit 1def775
26 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -686,6 +686,16 @@ PyConfig | |||
| 686 | 686 | ||
| 687 | 687 | :data:`sys._xoptions`. | |
| 688 | 688 | ||
| 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 | + | ||
| 689 | 699 | If ``parse_argv`` is non-zero, ``argv`` arguments are parsed the same | |
| 690 | 700 | way the regular Python parses command line arguments, and Python | |
| 691 | 701 | arguments are stripped from ``argv``: see :ref:`Command Line Arguments | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -427,7 +427,7 @@ Miscellaneous options | |||
| 427 | 427 | ||
| 428 | 428 | * ``-X faulthandler`` to enable :mod:`faulthandler`; | |
| 429 | 429 | * ``-X oldparser``: enable the traditional LL(1) parser. See also | |
| 430 | - :envvar:`PYTHONOLDPARSER`. | ||
| 430 | + :envvar:`PYTHONOLDPARSER` and :pep:`617`. | ||
| 431 | 431 | * ``-X showrefcount`` to output the total reference count and number of used | |
| 432 | 432 | memory blocks when the program finishes or after each statement in the | |
| 433 | 433 | interactive interpreter. This only works on debug builds. | |
@@ -480,6 +480,9 @@ Miscellaneous options | |||
| 480 | 480 | ||
| 481 | 481 | The ``-X showalloccount`` option has been removed. | |
| 482 | 482 | ||
| 483 | + .. deprecated-removed:: 3.9 3.10 | ||
| 484 | + The ``-X oldparser`` option. | ||
| 485 | + | ||
| 483 | 486 | ||
| 484 | 487 | Options you shouldn't use | |
| 485 | 488 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | |
@@ -578,8 +581,11 @@ conflict. | |||
| 578 | 581 | ||
| 579 | 582 | .. envvar:: PYTHONOLDPARSER | |
| 580 | 583 | ||
| 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 | ||
| 583 | 589 | ||
| 584 | 590 | ||
| 585 | 591 | .. envvar:: PYTHONINSPECT | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,7 +149,7 @@ typedef struct { | |||
| 149 | 149 | ||
| 150 | 150 | /* Enable PEG parser? | |
| 151 | 151 | 1 by default, set to 0 by -X oldparser and PYTHONOLDPARSER */ | |
| 152 | - int use_peg; | ||
| 152 | + int _use_peg_parser; | ||
| 153 | 153 | ||
| 154 | 154 | /* Enable tracemalloc? | |
| 155 | 155 | Set by -X tracemalloc=N and PYTHONTRACEMALLOC. -1 means unset */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -326,7 +326,7 @@ def _args_from_interpreter_flags(): | |||
| 326 | 326 | if dev_mode: | |
| 327 | 327 | args.extend(('-X', 'dev')) | |
| 328 | 328 | for opt in ('faulthandler', 'tracemalloc', 'importtime', | |
| 329 | - 'showrefcount', 'utf8'): | ||
| 329 | + 'showrefcount', 'utf8', 'oldparser'): | ||
| 330 | 330 | if opt in xoptions: | |
| 331 | 331 | value = xoptions[opt] | |
| 332 | 332 | if value is True: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3454,3 +3454,13 @@ def wait_process(pid, *, exitcode, timeout=None): | |||
| 3454 | 3454 | # sanity check: it should not fail in practice | |
| 3455 | 3455 | if pid2 != pid: | |
| 3456 | 3456 | 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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,12 +4,12 @@ | |||
| 4 | 4 | """ | |
| 5 | 5 | import sys | |
| 6 | 6 | import unittest | |
| 7 | - from test.support import is_jython | ||
| 7 | + from test import support | ||
| 8 | 8 | ||
| 9 | 9 | from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT | |
| 10 | 10 | import io | |
| 11 | 11 | ||
| 12 | - if is_jython: | ||
| 12 | + if support.is_jython: | ||
| 13 | 13 | ||
| 14 | 14 | def unify_callables(d): | |
| 15 | 15 | for n,v in d.items(): | |
@@ -21,7 +21,7 @@ class CodeopTests(unittest.TestCase): | |||
| 21 | 21 | ||
| 22 | 22 | def assertValid(self, str, symbol='single'): | |
| 23 | 23 | '''succeed iff str is a valid piece of code''' | |
| 24 | - if is_jython: | ||
| 24 | + if support.is_jython: | ||
| 25 | 25 | code = compile_command(str, "<input>", symbol) | |
| 26 | 26 | self.assertTrue(code) | |
| 27 | 27 | if symbol == "single": | |
@@ -60,7 +60,7 @@ def test_valid(self): | |||
| 60 | 60 | av = self.assertValid | |
| 61 | 61 | ||
| 62 | 62 | # special case | |
| 63 | - if not is_jython: | ||
| 63 | + if not support.is_jython: | ||
| 64 | 64 | self.assertEqual(compile_command(""), | |
| 65 | 65 | compile("pass", "<input>", 'single', | |
| 66 | 66 | PyCF_DONT_IMPLY_DEDENT)) | |
@@ -122,7 +122,7 @@ def test_valid(self): | |||
| 122 | 122 | av("def f():\n pass\n#foo\n") | |
| 123 | 123 | av("@a.b.c\ndef f():\n pass\n") | |
| 124 | 124 | ||
| 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") | ||
| 126 | 126 | def test_incomplete(self): | |
| 127 | 127 | ai = self.assertIncomplete | |
| 128 | 128 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -501,7 +501,7 @@ def test_single_statement(self): | |||
| 501 | 501 | self.compile_single("if x:\n f(x)\nelse:\n g(x)") | |
| 502 | 502 | self.compile_single("class T:\n pass") | |
| 503 | 503 | ||
| 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') | ||
| 505 | 505 | def test_bad_single_statement(self): | |
| 506 | 506 | self.assertInvalidSingle('1\n2') | |
| 507 | 507 | self.assertInvalidSingle('def f(): pass') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -347,7 +347,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): | |||
| 347 | 347 | 'isolated': 0, | |
| 348 | 348 | 'use_environment': 1, | |
| 349 | 349 | 'dev_mode': 0, | |
| 350 | - 'use_peg': 1, | ||
| 350 | + '_use_peg_parser': 1, | ||
| 351 | 351 | ||
| 352 | 352 | 'install_signal_handlers': 1, | |
| 353 | 353 | 'use_hash_seed': 0, | |
@@ -729,7 +729,7 @@ def test_init_from_config(self): | |||
| 729 | 729 | 'import_time': 1, | |
| 730 | 730 | 'show_ref_count': 1, | |
| 731 | 731 | 'malloc_stats': 1, | |
| 732 | - 'use_peg': 0, | ||
| 732 | + '_use_peg_parser': 0, | ||
| 733 | 733 | ||
| 734 | 734 | 'stdio_encoding': 'iso8859-1', | |
| 735 | 735 | 'stdio_errors': 'replace', | |
@@ -792,6 +792,7 @@ def test_init_compat_env(self): | |||
| 792 | 792 | 'user_site_directory': 0, | |
| 793 | 793 | 'faulthandler': 1, | |
| 794 | 794 | 'warnoptions': ['EnvVar'], | |
| 795 | + '_use_peg_parser': 0, | ||
| 795 | 796 | } | |
| 796 | 797 | self.check_all_configs("test_init_compat_env", config, preconfig, | |
| 797 | 798 | api=API_COMPAT) | |
@@ -819,6 +820,7 @@ def test_init_python_env(self): | |||
| 819 | 820 | 'user_site_directory': 0, | |
| 820 | 821 | 'faulthandler': 1, | |
| 821 | 822 | 'warnoptions': ['EnvVar'], | |
| 823 | + '_use_peg_parser': 0, | ||
| 822 | 824 | } | |
| 823 | 825 | self.check_all_configs("test_init_python_env", config, preconfig, | |
| 824 | 826 | api=API_PYTHON) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,7 @@ def test_EOFS(self): | |||
| 26 | 26 | else: | |
| 27 | 27 | raise support.TestFailed | |
| 28 | 28 | ||
| 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") | ||
| 30 | 30 | def test_line_continuation_EOF(self): | |
| 31 | 31 | """A continuation at the end of input must be an error; bpo2180.""" | |
| 32 | 32 | expect = 'unexpected EOF while parsing (<string>, line 1)' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,7 +178,7 @@ def ckmsg(src, msg, exception=SyntaxError): | |||
| 178 | 178 | s = '''if True:\n print()\n\texec "mixed tabs and spaces"''' | |
| 179 | 179 | ckmsg(s, "inconsistent use of tabs and spaces in indentation", TabError) | |
| 180 | 180 | ||
| 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") | ||
| 182 | 182 | def testSyntaxErrorOffset(self): | |
| 183 | 183 | def check(src, lineno, offset, encoding='utf-8'): | |
| 184 | 184 | with self.assertRaises(SyntaxError) as cm: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments