[issue4423] 2to3 replaces "arbitrary" variables

Martin v. Löwis report at bugs.python.org
Wed Nov 26 00:10:12 CET 2008


Martin v. Löwis <martin at v.loewis.de> added the comment:

> I'm not sure what you mean about MAPPING being compiled in. It is
> regenerated every time 2to3 is run.

This code does not work:

    from lib2to3.fixes import fix_imports
    del fix_imports.MAPPING['commands']

when followed by an attempt to actually run the fixer. Instead, I need
to write

    from lib2to3.fixes import fix_imports
    del fix_imports.MAPPING['commands']
    fix_imports.FixImports.PATTERN="|".join(fix_imports.build_pattern())

> Anyway, I fixed the replacement problem in r67386.

Thanks! It still transforms

def g():
    import commands
def f():
    commands = foo()
    commands.sort()

but I think this is ok; people just shouldn't write such code in the
first place (and the resulting code does work correctly - just with
a strangely-renamed local variable).

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


More information about the Python-bugs-list mailing list