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 fix_renames doesn't rename string.lowercase/uppercase/letters
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder: Close 2to3 issues and list them here
View: 45544
Assigned To: Nosy List: Anthony.Kong, aldwinaldwin, benjamin.peterson, ezio.melotti, meador.inge, superluser
Priority: normal Keywords: easy, patch

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) * (Python committer) 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:23adminsetgithub: 57481
2021-10-20 22:58:48iritkatrielsetstatus: open -> closed
superseder: Close 2to3 issues and list them here
resolution: wont fix
stage: patch review -> resolved
2019-07-18 08:42:25aldwinaldwinsetnosy: + aldwinaldwin
messages: + msg348107
2019-07-18 08:34:06aldwinaldwinsetstage: test needed -> patch review
pull_requests: + pull_request14626
2019-04-26 20:34:34BreamoreBoysetnosy: - BreamoreBoy
2014-09-09 20:55:39superlusersetmessages: + msg226660
2014-09-09 20:52:39superlusersetfiles: + string_partial.patch

nosy: + superluser
messages: + msg226659

keywords: + patch
2014-07-28 02:53:49Anthony.Kongsetnosy: + Anthony.Kong
2014-06-28 22:17:07ezio.melottisetkeywords: + easy
2014-06-28 18:22:48BreamoreBoysetnosy: + BreamoreBoy

messages: + msg221808
versions: + Python 3.4, Python 3.5, - Python 3.2, Python 3.3
2011-10-27 14:07:22meador.ingesetnosy: + meador.inge
2011-10-27 07:27:05ezio.melotticreate