Guido rethinking removal of cmp from sort method
Terry Reedy
tjreedy at udel.edu
Fri Apr 1 22:21:33 EDT 2011
On 4/1/2011 3:22 PM, Paul Rubin wrote:
>> 2to3 could probably gain a fixer to change
>> .sort(cmp=f) # to
>>
>> import functools import cmp_to_key
>> .sort(key=functools.cmp_to_key(f))
>>
>> I know some would not like this because interface change is not their
>> real concern.
>
> Looks like a good idea. There is an efficiency hit from the above in
> some situations, but at least it prevents code from breaking, so unless
> there's some drawback I'm not currently spotting, it's better than
> nothing and I'd endorse adding such a wrapper. 2to3 should show some
> kind of diagnostic and maybe put a comment into the output code,
> when it does that particular transformation, since most of the
> time there's probably a better way to write the key function.
rewriting cmp_to_key in C is underway
http://bugs.python.org/issue11707
--
Terry Jan Reedy
More information about the Python-list
mailing list