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
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
8 changes: 4 additions & 4 deletions 8 Doc/library/parser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions 4 Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand Down
9 changes: 9 additions & 0 deletions 9 Lib/test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Comment thread
pablogsal marked this conversation as resolved.


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The :mod:`parser` module is deprecated and will be removed in future
versions of Python.
6 changes: 6 additions & 0 deletions 6 Modules/parsermodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

@pablogsal pablogsal Jul 30, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 is the magic number to skip all importlib._bootstrap_external (tested in test_deprecation_message). 🙃

return NULL;
}

if (PyType_Ready(&PyST_Type) < 0)
return NULL;
module = PyModule_Create(&parsermodule);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.