classification
Title: 2to3 fix_renames doesn't rename string.lowercase/uppercase/letters
Type: behavior Stage: test needed
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Anthony.Kong, benjamin.peterson, ezio.melotti, meador.inge, superluser
Priority: normal Keywords: easy, patch

Created on 2011-10-27 07:27 by ezio.melotti, last changed 2019-04-26 20:34 by BreamoreBoy.

Files
File name Uploaded Description Edit
string_partial.patch superluser, 2014-09-09 20:52 review
Messages (4)
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 :\
History
Date User Action Args
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