[Python-checkins] r64651 - sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py

Brett Cannon brett at python.org
Mon Jul 7 21:00:45 CEST 2008


On Mon, Jul 7, 2008 at 10:08 AM, Nick Edds <nedds at uchicago.edu> wrote:
> For star imports, should I handle them in the same way that fix_imports
> handles them, i.e. just give a warning and avoid fixing them?
>

I think so, especially in this situation where you would be importing
even more modules and thus more names than in the other case handled
by fix_imports.

-Brett


> On Sat, Jul 5, 2008 at 10:01 PM, Collin Winter <collinw at gmail.com> wrote:
>>
>> On Sat, Jul 5, 2008 at 7:37 PM, Brett Cannon <brett at python.org> wrote:
>> > On Sat, Jul 5, 2008 at 10:16 AM, Nick Edds <nedds at uchicago.edu> wrote:
>> >> Brett,
>> >>
>> >> If you want me to try and make this a fixer, I can give it a shot over
>> >> the
>> >> next few days because I'm already fairly comfortable with fixers in
>> >> 2to3. I
>> >> think based on the revision that was attempted and what I've read
>> >> online, I
>> >> have a pretty good idea of what needs to be done with this fixer.
>> >> Hopefully
>> >> I'll have the time to get this done by Monday or Tuesday if you'd like
>> >> me to
>> >> do it.
>> >>
>> >
>> > Go for it! Basically the fixer needs to deal with the fact that urllib
>> > and urllib2 now span multiple modules. So as Collin mentioned, you
>> > probably should import all the modules they span across and then
>> > update the references in the code appropriately. Trick is going to be
>> > situations where the modules are imported as something else, e.g.,
>> > ``import urllib as spam`` since that won't work when the modules have
>> > multiple names. But since I suspect that is a rare case it might just
>> > have to be a warning or something.
>>
>> Agreed. I think we can just warn in this case, rather than wasting
>> time catering to rarities like this.
>>
>> >> On Sat, Jul 5, 2008 at 11:58 AM, Brett Cannon <brett at python.org> wrote:
>> >>>
>> >>> On Fri, Jul 4, 2008 at 6:22 PM, Collin Winter <collinw at gmail.com>
>> >>> wrote:
>> >>> > On Tue, Jul 1, 2008 at 7:00 PM, brett.cannon
>> >>> > <python-checkins at python.org> wrote:
>> >>> >> Author: brett.cannon
>> >>> >> Date: Wed Jul  2 04:00:11 2008
>> >>> >> New Revision: 64651
>> >>> >>
>> >>> >> Log:
>> >>> >> Update fix_imports for urllib. Had to change the fixer itself to
>> >>> >> handle
>> >>> >> modules
>> >>> >> that are split across several renames in 3.0.
>> >>> >
>> >>> > So I realize that you already reverted this, but I thought to
>> >>> > comment
>> >>> > anyway: this implementation is almost certainly wrong. Any fixer for
>> >>> > this particular PEP 3108 change will need to possibly insert extra
>> >>> > imports to handle the new urllib.request/error/etc modules. I think
>> >>> > this kind of thing should be broken into its own fixer, or at least
>> >>> > its own distinct functionality inside of fix_imports.
>> >>> >
>> >>>
>> >>> OK. I will see if I can figure out how this works at some point.
>> >>>
>> >>> > Nick Edds is working to speed up fix_imports by stripping out the
>> >>> > member matching stuff, which we don't believe to be actually useful
>> >>> > in
>> >>> > the majority of module renamings. IMHO there should be two different
>> >>> > mappings: one for bare-bones module renames (StringIO -> io), and a
>> >>> > separate one for more complex renames, like urllib/urllib2. That
>> >>> > will
>> >>> > allow optimizing the former larger pattern while preserving
>> >>> > flexibility for the rare cases in the latter.
>> >>> >
>> >>>
>> >>> Makes sense.
>> >>>
>> >>> -Brett
>> >>
>> >>
>> >
>
>


More information about the Python-checkins mailing list