Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the 2to3 program and the lib2to3 module #104780

Closed
vstinner opened this issue May 23, 2023 · 3 comments
Closed

Remove the 2to3 program and the lib2to3 module #104780

vstinner opened this issue May 23, 2023 · 3 comments

Comments

@vstinner
Copy link
Member

vstinner commented May 23, 2023

The 2to3 program is implemented with the lib2to3 module which implements a parser of the Python language. Problem: this parser is unable to parse Python 3.10 grammar :-( This issue was already known in Python 3.9 when PEP 617 – New PEG parser for CPython was approved.

The 2to3 program and the lib2to3 were marked as "pending" deprecated since Python 3.9, and then officially deprecated in Python 3.11 (import lib2to3 emits a DeprecationWarning).

One of a famous user of lib2to3 was the black project but they decided to fork lib2to3 and their fork was made compatible with Python 3.10 grammar (maybe also Python 3.11).

I propose to remove 2to3 and lib2to3 at the beginning of the Python 3.13 development cycle to give users more time to be prepared for this incompatible change before Python 3.13 final release (scheduled in October 2024).

cc @isidentical @lysnikolaou @pablogsal @ambv


Example of valid Python script (script.py:

with (open(__file__) as fp): data=fp.read()
print(len(data))

It works well on Python 3.11:

$ python3.11 script.py 
61

But lib2to3 is unable to parse it:

$ python3.11 -m lib2to3 script.py 
(...)
RefactoringTool: No files need to be modified.
RefactoringTool: There was 1 error:
RefactoringTool: Can't parse script.py: ParseError: bad input: type=1, value='as', context=(' ', (1, 21))

Linked PRs

vstinner added a commit to vstinner/cpython that referenced this issue May 23, 2023
* Remove the Tools/scripts/2to3 script.
* Remove the Lib/test/test_lib2to3/ directory.
* Doc/tools/extensions/pyspecific.py: remove the "2to3fixer" object
  type.
* Makefile and PC/layout/main.py no longer compile lib2to3 grammar
  files.
* Update Makefile for 2to3 removal.
vstinner added a commit that referenced this issue May 23, 2023
* Remove the Tools/scripts/2to3 script.
* Remove the Lib/test/test_lib2to3/ directory.
* Doc/tools/extensions/pyspecific.py: remove the "2to3fixer" object
  type.
* Makefile and PC/layout/main.py no longer compile lib2to3 grammar
  files.
* Update Makefile for 2to3 removal.
@vstinner
Copy link
Member Author

Done by ae00b81

@hugovk
Copy link
Member

hugovk commented May 23, 2023

Wow!

+26 -21,000

(I think this issue can be closed, please re-open otherwise :)

@hugovk hugovk closed this as completed May 23, 2023
@vstinner
Copy link
Member Author

lib2to3 was deprecated in Python 3.11 by issue #84540.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants