mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #11707: Fast C version of functools.cmp_to_key()
This commit is contained in:
parent
271b27e5fe
commit
7ab9e22e34
4 changed files with 235 additions and 2 deletions
|
@ -97,7 +97,7 @@ def cmp_to_key(mycmp):
|
|||
"""Convert a cmp= function into a key= function"""
|
||||
class K(object):
|
||||
__slots__ = ['obj']
|
||||
def __init__(self, obj, *args):
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
def __lt__(self, other):
|
||||
return mycmp(self.obj, other.obj) < 0
|
||||
|
@ -115,6 +115,11 @@ def cmp_to_key(mycmp):
|
|||
raise TypeError('hash not implemented')
|
||||
return K
|
||||
|
||||
try:
|
||||
from _functools import cmp_to_key
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
_CacheInfo = namedtuple("CacheInfo", "hits misses maxsize currsize")
|
||||
|
||||
def lru_cache(maxsize=100):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue