This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Double parenthesis in print function running 2to3 in already correct call
Type: Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions:
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: benjamin.peterson, jondaa, p-ganssle, vstinner, xtreak
Priority: normal Keywords:

Created on 2018-12-05 10:10 by jondaa, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg331098 - (view) Author: Jonathan Alush-Aben (jondaa) Date: 2018-12-05 10:10
If 2to3 is run on a file with the following contents:
print ("%s" % a)

The output is:

print (("%s" % a))

Although it was already a valid call to print in python3.
msg331104 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-05 12:33
Thanks for the report. Is this similar to issue10375 ? One option would be to use -p to stop transforming print related code if you don't want to transform any print statement.

$ cat /tmp/
print (1)

$ 2to3 /tmp/
--- /tmp/	(original)
+++ /tmp/	(refactored)
@@ -1 +1 @@
-print (1)

$ 2to3 -p /tmp/
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: No files need to be modified.
msg336691 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-02-26 16:30
I suggest to close this issue as WONTFIX.

2to3 is designed as a tool to convert a Python 2 code base to Python 3 at once. I understand that once the code base is converted, you may want to revert some unwanted "useless" changes.

Python 2 and Python 3 languages have some intersections where it's hard to guess if the code is valid or not in Python 3. 2to3 uses heuristic which implements practical solutions. And you noticed, there are some corner cases where 2to3 generates useless changes.

IMHO 2to3 is fine. It may be nice to enhance it, but well, it's a trade-off, it's good as it is.

You may want to test other tools like modernize, 2to6, sixer, etc. which made different trade-offs.

Note: I'm the author of sixer and I'm not a big of 2to3 since it drops Python 2 support and generate many changes which are not needed since Python 3.2.
msg336762 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-02-27 14:37
> 2to3 is designed as a tool to convert a Python 2 code base to Python 3 at once. I understand that once the code base is converted, you may want to revert some unwanted "useless" changes.

While this problem is likely to show up because someone has run 2to3 on a codebase more than once, I have *always* used parentheses around my print statements, even in pure Python 2, so it's not necessarily the case that this will cause problems.

I think this is a legitimate bug but also harmless since the code it generates is equivalent to the version with only one set of parentheses. I don't see a great deal of harm in marking this as low priority and leaving the bug open for someone to fix later, other than the fact that if someone comes along and fixes it, they may be discouraged to find that there are not really core developers interested in reviewing and merging the PR.

I will note that with the end of Python 2, 2to3 may become *more* relevant as fewer and fewer people are looking to translate code from 2->2/3 and more people will be looking to translate 2->3 directly.
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79598
2021-10-20 22:49:46iritkatrielsetstatus: open -> closed
resolution: wont fix
superseder: Close 2to3 issues and list them here
stage: resolved
2019-02-27 14:37:42p-gansslesetnosy: + p-ganssle
messages: + msg336762
2019-02-26 16:30:29vstinnersetnosy: + vstinner
messages: + msg336691
2018-12-05 12:33:08xtreaksetnosy: + benjamin.peterson, xtreak
messages: + msg331104
2018-12-05 10:10:19jondaacreate