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: Regression fix_imports does not refactor multiple imports correctly
Type: behavior Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, benjamin.peterson, lregebro
Priority: normal Keywords:

Created on 2008-12-14 19:07 by lregebro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test3.py lregebro, 2008-12-14 20:54
Messages (8)
msg77815 - (view) Author: Lennart Regebro (lregebro) Date: 2008-12-14 19:07
If you have urlparse before cStringIO in an import line, 2to3 will not
convert the cStringIO to io. However, reverse the order, and urlparse
will not get translated.

So this file:
import urlparse, cStringIO
import cStringIO, urlparse

will with 2to3 return the following diff:

--- test3.py (original)
+++ test3.py (refactored)
@@ -1,3 +1,3 @@
 
-import urlparse, cStringIO
-import cStringIO, urlparse
+import urllib.parse, cStringIO
+import io, urlparse
msg77816 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2008-12-14 19:20
Sorry, I still cannot reproduce it. Could you attach your test file?
Maybe it is some weird encoding bug.

alex@helios:~$ 2to3 -f imports test.py
--- test.py (original)
+++ test.py (refactored)
@@ -1,2 +1,2 @@
-import urlparse, cStringIO
-import cStringIO, urlparse
+import urllib.parse, io
+import io, urllib.parse
RefactoringTool: Files that need to be modified:
RefactoringTool: test.py
msg77819 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-12-14 19:50
Here's one which doesn't work correctly:

$ 2to3 -
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
import cStringIO, HTMLParser
--- <stdin> (original)
+++ <stdin> (refactored)
@@ -1,1 +1,1 @@
-import cStringIO, HTMLParser
+import io, HTMLParser
RefactoringTool: Files that need to be modified:
RefactoringTool: <stdin>

This is because the fix_imports pattern catching one module per import
statement.
msg77824 - (view) Author: Lennart Regebro (lregebro) Date: 2008-12-14 20:54
Heres my test file.
msg77825 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2008-12-14 21:06
Benjamin, your example fails for a different reason--i.e. the fixer for
HTMLParser is missing.

Sorry Lennart, I still cannot reproduce it.
msg77827 - (view) Author: Lennart Regebro (lregebro) Date: 2008-12-14 21:11
What version are you running? Can you post the output?
msg77831 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2008-12-14 21:22
I got it. It is a regression from a previous version of 2to3's
fix_imports. I was able to reproduce your problem using the sandbox's 2to3.

And to answer your question, I still running an older RC release of
Python 3.0. That explains why I couldn't reproduce the problem.

$ python3.0 -c "import sys; print(sys.version)"
3.0rc2+ (py3k:67237, Nov 16 2008, 15:10:03) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)]
msg77839 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-12-14 21:55
Fixed in r67774.
History
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48914
2008-12-14 21:55:51benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg77839
2008-12-14 21:22:44alexandre.vassalottisetmessages: + msg77831
title: fix_imports does not refactor "import urlparse, cStringIO" correctly -> Regression fix_imports does not refactor multiple imports correctly
2008-12-14 21:11:04lregebrosetmessages: + msg77827
2008-12-14 21:06:58alexandre.vassalottisetmessages: + msg77825
2008-12-14 20:54:08lregebrosetfiles: + test3.py
messages: + msg77824
2008-12-14 19:50:52benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg77819
2008-12-14 19:20:14alexandre.vassalottisetnosy: + alexandre.vassalotti
messages: + msg77816
title: import urlparse, cStringIO breaks -> fix_imports does not refactor "import urlparse, cStringIO" correctly
2008-12-14 19:07:20lregebrocreate