Issue 13272: 2to3 fix_renames doesn't rename string.lowercase/uppercase/letters
Issue13272
Created on 2011-10-27 07:27 by ezio.melotti, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| string_partial.patch | superluser, 2014-09-09 20:52 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 14835 | closed | aldwinaldwin, 2019-07-18 08:34 | |
| Messages (5) | |||
|---|---|---|---|
| msg146475 - (view) | Author: Ezio Melotti (ezio.melotti) * ![]() |
Date: 2011-10-27 07:27 | |
$ 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_*.
|
|||
| msg221808 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2014-06-28 18:22 | |
@Ezio can you prepare a patch for this? |
|||
| msg226659 - (view) | Author: Rose Ames (superluser) * | Date: 2014-09-09 20:52 | |
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:
```
def imap(): pass
imap()
```
to
```
def imap(): pass
map()
```
This patch is a little smarter than that, but it only detects top-level definitions. For example, the lowercase in
```
class Foo:
def __init__(self):
self.lowercase = "blargh"
```
still gets renamed.
I can work on this more, but would like to know:
a) whether this fix is still wanted
b) how smart it needs to be
c) whether my approach is reasonable. I feel like there should be an easier way.
|
|||
| msg226660 - (view) | Author: Rose Ames (superluser) * | Date: 2014-09-09 20:55 | |
... d) how to format code :\ |
|||
| msg348107 - (view) | Author: Aldwin Pollefeyt (aldwinaldwin) * | Date: 2019-07-18 08:42 | |
* there were many small issues with the patch, improved as good as possible the FixString to catch ```import as```, ```from string import *``` and ```import string``` * did not include the FixStringImports as it's not a necessity to work in Python3 * indeed, some uses of the constant names that are user-defined will also rename, only when it's in a ```import string```. Added a ```Caution``` in the documentation. Still, when all are changed, it should not affect the Python3 version, will just work with the renamed variable name. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:23 | admin | set | github: 57481 |
| 2021-10-20 22:58:48 | iritkatriel | set | status: open -> closed superseder: Close 2to3 issues and list them here resolution: wont fix stage: patch review -> resolved |
| 2019-07-18 08:42:25 | aldwinaldwin | set | nosy:
+ aldwinaldwin messages: + msg348107 |
| 2019-07-18 08:34:06 | aldwinaldwin | set | stage: test needed -> patch review pull_requests: + pull_request14626 |
| 2019-04-26 20:34:34 | BreamoreBoy | set | nosy:
- BreamoreBoy |
| 2014-09-09 20:55:39 | superluser | set | messages: + msg226660 |
| 2014-09-09 20:52:39 | superluser | set | files:
+ string_partial.patch nosy:
+ superluser keywords: + patch |
| 2014-07-28 02:53:49 | Anthony.Kong | set | nosy:
+ Anthony.Kong |
| 2014-06-28 22:17:07 | ezio.melotti | set | keywords: + easy |
| 2014-06-28 18:22:48 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages:
+ msg221808 |
| 2011-10-27 14:07:22 | meador.inge | set | nosy:
+ meador.inge |
| 2011-10-27 07:27:05 | ezio.melotti | create | |
