[Python-Dev] 2to3 question about fix_imports.

Alexandre Vassalotti alexandre at peadrop.com
Sun Dec 14 19:19:17 CET 2008


On Fri, Dec 12, 2008 at 11:39 AM, Lennart Regebro <regebro at gmail.com> wrote:
> The fix_imports fix seems to fix only the first import per line that you have.
> So if you do for example
> import urllib2, cStringIO
> it will not fix cStringIO.
>> Is this a bug or a feature? :-) If it's a feature it should warn at
> least, right?
>
Which revision of python are you using? I tried the test-case you gave
and 2to3 translated it perfectly.
-- Alexandre
alex at helios:~$ cat test.py
import urllib2, cStringIO
s = cStringIO.StringIO(urllib2.randombytes(100))
alex at helios:~$ 2to3 test.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
--- test.py (original)
+++ test.py (refactored)
@@ -1,3 +1,3 @@
-import urllib2, cStringIO
+import urllib.request, urllib.error, io
-s = cStringIO.StringIO(urllib2.randombytes(100))
+s = io.StringIO(urllib2.randombytes(100))
RefactoringTool: Files that need to be modified:
RefactoringTool: test.py


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /