Issue 4664: Regression fix_imports does not refactor multiple imports correctly (original) (raw)

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 --- (original) +++ (refactored) @@ -1,1 +1,1 @@ -import cStringIO, HTMLParser +import io, HTMLParser RefactoringTool: Files that need to be modified: RefactoringTool: 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:42 admin set github: 48914
2008-12-14 21:55:51 benjamin.peterson set status: open -> closedresolution: fixedmessages: +
2008-12-14 21:22:44 alexandre.vassalotti set messages: + title: fix_imports does not refactor "import urlparse, cStringIO" correctly -> Regression fix_imports does not refactor multiple imports correctly
2008-12-14 21:11:04 lregebro set messages: +
2008-12-14 21:06:58 alexandre.vassalotti set messages: +
2008-12-14 20:54:08 lregebro set files: + test3.pymessages: +
2008-12-14 19:50:52 benjamin.peterson set nosy: + benjamin.petersonmessages: +
2008-12-14 19:20:14 alexandre.vassalotti set nosy: + alexandre.vassalottimessages: + title: import urlparse, cStringIO breaks -> fix_imports does not refactor "import urlparse, cStringIO" correctly
2008-12-14 19:07:20 lregebro create