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.

classification
Title: 2to3 does not support integer division fixing
Type: enhancement Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool), Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Crowthebird, eric.smith, lukasz.langa
Priority: normal Keywords: patch

Created on 2021-11-06 11:50 by Crowthebird, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29440 closed Crowthebird, 2021-11-06 11:54
Messages (6)
msg405857 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-06 11:50
Right now, 2to3 does not support integer division fixing. Supposing `test.py` is a file with these contents:
x = 2 ** 8 / 5 / 7

Here's an example:
C:\Users\admin> py -m lib2to3 test.py
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.
msg405862 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-06 14:34
When 2to3 supports integer division fixing, there would be this behaviour:

- x = 2 ** 8 / 5 / 7
+ x = 2 ** 8 // 5 // 7

Basically convert any integer division to floor division. The PR I made only works for constant integers, and any improvement would be appreciated.
msg405884 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-11-06 19:47
I think knowing that that's integer division is beyond what 2to3 can accomplish. Plus, with lib2to3 being deprecated, I don't think anyone's going to put any effort into this.
msg405889 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-06 23:09
I have put some effort to make it work for constant integers. So this

x = a ** 3 / 7

would not be changed, since it refers to a name whose value is not known.
msg405892 - (view) Author: Jeremiah Gabriel Pascual (Crowthebird) * Date: 2021-11-07 03:46
A correction to the discussion: The PR I made only fixes CONSTANT integer division, not any other. The left and right operands are checked for non-constants and then are checked for integerness (specifically checks for `NOT A FLOAT`s). After both checks have passed, the division operator is turned into a floor division operator.
msg406551 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-11-18 16:17
We don't accept new features for 3.10 anymore, and since 2to3 is deprecated, we won't be updating it with new fixers and so on. It is pending removal in Python 3.13.

Sorry, I understand this is a bummer but this part of Python hasn't seen serious development for the past few years and its parser is incompatible with modern 3.9+ code.
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89899
2021-11-18 16:17:37lukasz.langasetstatus: open -> closed

nosy: + lukasz.langa
messages: + msg406551

resolution: wont fix
stage: patch review -> resolved
2021-11-07 03:53:16Crowthebirdsetversions: - Python 3.9, Python 3.11
2021-11-07 03:53:03Crowthebirdsetversions: + Python 3.9, Python 3.11
2021-11-07 03:46:11Crowthebirdsetmessages: + msg405892
2021-11-06 23:09:58Crowthebirdsetmessages: + msg405889
2021-11-06 19:47:02eric.smithsetnosy: + eric.smith
messages: + msg405884
2021-11-06 14:34:27Crowthebirdsetmessages: + msg405862
2021-11-06 14:31:05Crowthebirdsettype: enhancement
2021-11-06 11:54:42Crowthebirdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request27694
2021-11-06 11:50:26Crowthebirdcreate