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.

Author benjamin.peterson
Recipients benjamin.peterson, loewis
Date 2008-11-25.23:26:06
SpamBayes Score 1.7355062e-11
Marked as misclassified No
Message-id <1afaf6160811251526r6ce4b9c8n4a25f6d0a2d1d81b@mail.gmail.com>
In-reply-to <492C85D0.1010603@v.loewis.de>
Content
On Tue, Nov 25, 2008 at 5:10 PM, Martin v. Löwis <report@bugs.python.org> wrote:
>
> Martin v. Löwis <martin@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())

This is true of many fixers. What is the use case?

>
>> 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).

This also won't work:

def f():
    commands.call() # This fails to be fixed.

import commands

Is that reasonable also?

Scoping isn't something that 2to3 does well, and we'd probably have to
add a whole symtable analyzer to fix a few obscure bugs like above.
History
Date User Action Args
2008-11-25 23:26:08benjamin.petersonsetrecipients: + benjamin.peterson, loewis
2008-11-25 23:26:07benjamin.petersonlinkissue4423 messages
2008-11-25 23:26:06benjamin.petersoncreate