[Python-checkins] r65442 - python/trunk/Lib/pstats.py

brett.cannon python-checkins at python.org
Mon Aug 4 00:52:42 CEST 2008


Author: brett.cannon
Date: Mon Aug  4 00:52:42 2008
New Revision: 65442

Log:
Silence -3 warnings in pstats: a dict.has_key() usage and backport solution to
move from list.sort(cmp=) to key=.


Modified:
   python/trunk/Lib/pstats.py

Modified: python/trunk/Lib/pstats.py
==============================================================================
--- python/trunk/Lib/pstats.py	(original)
+++ python/trunk/Lib/pstats.py	Mon Aug  4 00:52:42 2008
@@ -140,7 +140,7 @@
             self.total_calls += nc
             self.prim_calls  += cc
             self.total_tt    += tt
-            if callers.has_key(("jprofile", 0, "profiler")):
+            if ("jprofile", 0, "profiler") in callers:
                 self.top_level[func] = None
             if len(func_std_string(func)) > self.max_name_len:
                 self.max_name_len = len(func_std_string(func))
@@ -238,7 +238,7 @@
             stats_list.append((cc, nc, tt, ct) + func +
                               (func_std_string(func), func))
 
-        stats_list.sort(TupleComp(sort_tuple).compare)
+        stats_list.sort(key=CmpToKey(TupleComp(sort_tuple).compare))
 
         self.fcn_list = fcn_list = []
         for tuple in stats_list:
@@ -471,6 +471,16 @@
                 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)
 


More information about the Python-checkins mailing list