mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Add tests for cmp_to_key.
Adopt PEP 8 compliant function name. Factor-out existing uses cmp_to_key. Update documentation to use internal pointers instead of external resource.
This commit is contained in:
parent
4f185228b0
commit
bb006cf26c
8 changed files with 17 additions and 31 deletions
|
@ -6,23 +6,13 @@ import sys
|
|||
import traceback
|
||||
import types
|
||||
|
||||
from functools import cmp_to_key as _CmpToKey
|
||||
from fnmatch import fnmatch
|
||||
|
||||
from . import case, suite
|
||||
|
||||
__unittest = True
|
||||
|
||||
|
||||
def _CmpToKey(mycmp):
|
||||
'Convert a cmp= function into a key= function'
|
||||
class K(object):
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
def __lt__(self, other):
|
||||
return mycmp(self.obj, other.obj) == -1
|
||||
return K
|
||||
|
||||
|
||||
# what about .pyc or .pyo (etc)
|
||||
# we would need to avoid loading the same tests multiple times
|
||||
# from '.py', '.pyc' *and* '.pyo'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue