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
2to3 fix_renames doesn't rename string.lowercase/uppercase/letters #57481
Comments
$ cat deleteme.py
from string import lowercase, uppercase, letters
print uppercase == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print lowercase == 'abcdefghijklmnopqrstuvwxyz'
print letters == 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
$ python deleteme.py
True
True
True
$ 2to3 -w 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,4 +1,4 @@
from string import lowercase, uppercase, letters
-print uppercase == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-print lowercase == 'abcdefghijklmnopqrstuvwxyz'
-print letters == 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+print(uppercase == 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
+print(lowercase == 'abcdefghijklmnopqrstuvwxyz')
+print(letters == 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
RefactoringTool: Files that were modified:
RefactoringTool: deleteme.py
$ python3 deleteme.py
Traceback (most recent call last):
File "deleteme.py", line 1, in <module>
from string import lowercase, uppercase, letters
ImportError: cannot import name lowercase They should be renamed to ascii_*. |
@ezio can you prepare a patch for this? |
Changing the imports only is straightforward, but I'm having trouble detecting and changing future uses of the variables, without also clobbering user-defined variables with the same names. I notice some of the current fixers have similar problems, for example the itertools fixer changes:
to
This patch is a little smarter than that, but it only detects top-level definitions. For example, the lowercase in
still gets renamed. I can work on this more, but would like to know: a) whether this fix is still wanted |
... d) how to format code :\ |
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: