[Python-checkins] bpo-37268: Add deprecation notice and a DeprecationWarning for the parser module (GH-15017)
Miss Islington (bot)
webhook-mailer at python.org
Tue Jul 30 07:04:24 EDT 2019
https://github.com/python/cpython/commit/9211e2fd81fe1db6f73ded70752b144cc9691ab6
commit: 9211e2fd81fe1db6f73ded70752b144cc9691ab6
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2019-07-30T04:04:01-07:00
summary:
bpo-37268: Add deprecation notice and a DeprecationWarning for the parser module (GH-15017)
Deprecate the parser module and add a deprecation warning triggered on import and a warning block in the documentation.
https://bugs.python.org/issue37268
Automerge-Triggered-By: @pablogsal
files:
A Misc/NEWS.d/next/Library/2019-07-30-01-27-29.bpo-37268.QDmA44.rst
M Doc/library/parser.rst
M Doc/whatsnew/3.9.rst
M Lib/test/test_parser.py
M Modules/parsermodule.c
diff --git a/Doc/library/parser.rst b/Doc/library/parser.rst
index a302681eca05..c55cd653b371 100644
--- a/Doc/library/parser.rst
+++ b/Doc/library/parser.rst
@@ -25,11 +25,11 @@ from this. This is better than trying to parse and modify an arbitrary Python
code fragment as a string because parsing is performed in a manner identical to
the code forming the application. It is also faster.
-.. note::
+.. warning::
- From Python 2.5 onward, it's much more convenient to cut in at the Abstract
- Syntax Tree (AST) generation and compilation stage, using the :mod:`ast`
- module.
+ The parser module is deprecated and will be removed in future versions of
+ Python. For the majority of use cases you can leverage the Abstract Syntax
+ Tree (AST) generation and compilation stage, using the :mod:`ast` module.
There are a few things to note about this module which are important to making
use of the data structures created. This is not a tutorial on editing the parse
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 85e254f061eb..273fd2b50d59 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -142,6 +142,10 @@ Deprecated
Python versions it will raise a :exc:`TypeError` for all floats.
(Contributed by Serhiy Storchaka in :issue:`37315`.)
+* The :mod:`parser` module is deprecated and will be removed in future versions
+ of Python. For the majority of use cases users can leverage the Abstract Syntax
+ Tree (AST) generation and compilation stage, using the :mod:`ast` module.
+
Removed
=======
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index e5285c636022..ec1845d7fe9a 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -6,6 +6,7 @@
import struct
from test import support
from test.support.script_helper import assert_python_failure
+from test.support.script_helper import assert_python_ok
#
# First, we test that we can generate trees from valid source fragments,
@@ -987,5 +988,13 @@ def test_two_args_to_expr(self):
with self.assertRaises(TypeError):
parser.expr("a", "b")
+
+class TestDeprecation(unittest.TestCase):
+ def test_deprecation_message(self):
+ code = "def f():\n import parser\n\nf()"
+ rc, out, err = assert_python_ok('-c', code)
+ self.assertIn(b'<string>:2: DeprecationWarning', err)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2019-07-30-01-27-29.bpo-37268.QDmA44.rst b/Misc/NEWS.d/next/Library/2019-07-30-01-27-29.bpo-37268.QDmA44.rst
new file mode 100644
index 000000000000..d5c7b1d2fc66
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-07-30-01-27-29.bpo-37268.QDmA44.rst
@@ -0,0 +1,2 @@
+The :mod:`parser` module is deprecated and will be removed in future
+versions of Python.
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 079d00f32aa6..b2495fc8b322 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1158,6 +1158,12 @@ PyInit_parser(void)
{
PyObject *module, *copyreg;
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "The parser module is deprecated and will be removed "
+ "in future versions of Python", 7) != 0) {
+ return NULL;
+ }
+
if (PyType_Ready(&PyST_Type) < 0)
return NULL;
module = PyModule_Create(&parsermodule);
More information about the Python-checkins
mailing list