[New-bugs-announce] [issue4909] incorrect renaming in imports

Martin v. Löwis report at bugs.python.org
Sat Jan 10 20:32:33 CET 2009


New submission from Martin v. Löwis <martin at v.loewis.de>:

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.

----------
components: 2to3 (2.x to 3.0 conversion tool)
messages: 79568
nosy: loewis
severity: normal
status: open
title: incorrect renaming in imports

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4909>
_______________________________________


More information about the New-bugs-announce mailing list