Issue 13253: 2to3 fix_renames renames sys.maxint only in imports - Python tracker

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
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: benjamin.peterson, eric.araujo, ezio.melotti, klimov, meador.inge
Priority: normal Keywords:

Created on 2011-10-24 06:25 by ezio.melotti, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg146278 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-10-24 06:25
$ cat deleteme.py 
from sys import maxint
print 'maxint', maxint
$ 2to3 deleteme.py 
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored deleteme.py
--- deleteme.py (original)
+++ deleteme.py (refactored)
@@ -1,2 +1,2 @@
-from sys import maxint
-print 'maxint', maxint
+from sys import maxsize
+print('maxint', maxint)
RefactoringTool: Files that need to be modified:
RefactoringTool: deleteme.py

The maxint in the print should be converted too.
msg146493 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-10-27 15:37
Do people really import maxint from sys?  I’d find that less readable than using sys.maxint —which should, if you ask me, also be replaced :)
msg146495 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-10-27 15:44
I do (or at least did it in at least one place :).
I think the problem is actually more general, and I don't know if it's by design.
If a name in the import is changed, all the other occurrences of the name should be changed as well.  I don't know if 2to3 is powerful enough to recognize what occurrences should be left untouched (e.g. if I also have maxsize = 100 inside a function), and how difficult would it be to do it.
See also #13272.
msg250802 - (view) Author: Nikita Klimov (klimov) Date: 2015-09-15 20:16
I'm interesting to research this. 
I can show results by 23 September, I think.
msg251460 - (view) Author: Nikita Klimov (klimov) Date: 2015-09-23 21:36
I'm close to solution, but I need another 1 week.
msg257275 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2016-01-01 05:29
Nikita, did you manage to find a solution?
If not, do you have a patch (even if not complete) to share?