[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

    import cStringIO as StringIO
except ImportError:
    import StringIO

gets rewritten to

    import io as StringIO
except ImportError:
    import io

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>

More information about the New-bugs-announce mailing list