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: incorrect renaming in imports
Type: Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, loewis
Priority: normal Keywords: patch

Created on 2009-01-10 19:32 by loewis, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cStringIO_hack.patch benjamin.peterson, 2009-01-10 21:12
Messages (4)
msg79568 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-10 19:32
The fragment

try:
    import cStringIO as StringIO
except ImportError:
    import StringIO
s=StringIO.StringIO()

gets rewritten to

try:
    import io as StringIO
except ImportError:
    import io
s=io.StringIO()

Unfortunately, that code fails to work: the first import succeeds,
actually binding StringIO; the name io is unbound and gives NameError.

Apparently, the fixer choses to replace all occurrences of StringIO with
io; it should extend this replacement to "as" clauses.

My work-around is to import as _StringIO in both cases, and then refer
to the module as _StringIO.
msg79576 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-01-10 21:03
Tricky. I only solution I can think of is replacing cStringIO with
_stringio or just refusing to replace StringIO usage once cStringIO has
been seen. The latter seems like the best solutions.
msg79577 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-10 21:07
If there is no straight-forward solution, we should close it as "won't
fix", and encourage users to work around.
msg79578 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-01-10 21:12
Ok. I will close this for now. This is a very common construct; if we
get more bug reports, we can reconsider. (I'm attaching the patch I used
to "fix" this for future reference.)
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49159
2009-01-10 21:12:25benjamin.petersonsetstatus: open -> closed
files: + cStringIO_hack.patch
messages: + msg79578
resolution: wont fix
keywords: + patch
2009-01-10 21:07:59loewissetmessages: + msg79577
2009-01-10 21:03:16benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg79576
2009-01-10 19:32:33loewiscreate