Skip to content

Commit 503de71

Browse files
authored
bpo-40360: Deprecate lib2to3 module in light of PEP 617 (GH-19663)
Deprecate lib2to3 module in light of PEP 617. We anticipate removal in the 3.12 timeframe.
1 parent 24ffe70 commit 503de71

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

Doc/library/2to3.rst

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
of *fixers* to transform it into valid Python 3.x code. The standard library
1010
contains a rich set of fixers that will handle almost all code. 2to3 supporting
1111
library :mod:`lib2to3` is, however, a flexible and generic library, so it is
12-
possible to write your own fixers for 2to3. :mod:`lib2to3` could also be
13-
adapted to custom applications in which Python code needs to be edited
14-
automatically.
12+
possible to write your own fixers for 2to3.
1513

1614

1715
.. _2to3-using:
@@ -466,9 +464,17 @@ and off individually. They are described here in more detail.
466464

467465
--------------
468466

467+
.. deprecated:: 3.10
468+
Python 3.9 will switch to a PEG parser (see :pep:`617`), and Python 3.10 may
469+
include new language syntax that is not parsable by lib2to3's LL(1) parser.
470+
The ``lib2to3`` module may be removed from the standard library in a future
471+
Python version. Consider third-party alternatives such as `LibCST`_ or
472+
`parso`_.
473+
469474
.. note::
470475

471476
The :mod:`lib2to3` API should be considered unstable and may change
472477
drastically in the future.
473478

474-
.. XXX What is the public interface anyway?
479+
.. _LibCST: https://libcst.readthedocs.io/
480+
.. _parso: https://parso.readthedocs.io/

Lib/lib2to3/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
#empty
1+
import warnings
2+
3+
4+
warnings.warn(
5+
"lib2to3 package is deprecated and may not be able to parse Python 3.10+",
6+
PendingDeprecationWarning,
7+
stacklevel=2,
8+
)

Lib/test/test___all__.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def check_all(self, modname):
1717
names = {}
1818
with support.check_warnings(
1919
(".* (module|package)", DeprecationWarning),
20+
(".* (module|package)", PendingDeprecationWarning),
2021
("", ResourceWarning),
2122
quiet=True):
2223
try:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :mod:`lib2to3` module is pending deprecation due to :pep:`617`.

0 commit comments

Comments
 (0)