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.
diff --git a/Lib/pstats.py b/Lib/pstats.py
index 0effa1c..8b60810 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -37,6 +37,7 @@
import time
import marshal
import re
+from functools import cmp_to_key
__all__ = ["Stats"]
@@ -238,7 +239,7 @@
stats_list.append((cc, nc, tt, ct) + func +
(func_std_string(func), func))
- stats_list.sort(key=CmpToKey(TupleComp(sort_tuple).compare))
+ stats_list.sort(key=cmp_to_key(TupleComp(sort_tuple).compare))
self.fcn_list = fcn_list = []
for tuple in stats_list:
@@ -471,16 +472,6 @@
return direction
return 0
-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
-
-
#**************************************************************************
# func_name is a triple (file:string, line:int, name:string)