[PATCH 1 of 3] import-checker: refactor sys.path prefix check (issue4129)

Augie Fackler raf at durin42.com
Tue Dec 24 16:52:23 CST 2013


On Dec 24, 2013, at 5:45 PM, Augie Fackler <raf at durin42.com> wrote:

> 
> On Dec 23, 2013, at 12:34 AM, Chris Jerdonek <chris.jerdonek at gmail.com> wrote:
> 
>> 
>>    for libpath in sys.path:
>> -        # We want to walk everything in sys.path that starts with
>> -        # either sys.prefix or sys.exec_prefix.
>> -        if not (libpath.startswith(sys.prefix)
>> -                or libpath.startswith(sys.exec_prefix)):
>> +        # We want to walk everything in sys.path that starts with something
>> +        # in stdlib_prefixes.
>> +        for prefix in stdlib_prefixes:
>> +            if libpath.startswith(prefix):
>> +                break
>> +        else:
>>            continue
> 
> This file already depends on 2.6isms (the ast module), so perhaps we could use any() here and avoid the slightly-awkward-to-me for/else? I think it might read more clearly.

After looking at the rest of the series, I'm crewing it with my own follow-up patch to use any() on a genexp instead of the for/break/else/continue trick. Thanks for following up on this!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20131224/ade6f260/attachment.pgp>


More information about the Mercurial-devel mailing list