diff options
author | Brett Cannon <bcannon@gmail.com> | 2008-08-03 22:52:42 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2008-08-03 22:52:42 (GMT) |
commit | c3ce0e53ad81263b20ef660722a4e65c40353654 (patch) | |
tree | 91f3a84057a20c24e4e1387962e344be8b7bfbe2 /Lib/pstats.py | |
parent | cc2f7b4994210cb415953d99124ca3a5f449cf39 (diff) | |
download | cpython-c3ce0e53ad81263b20ef660722a4e65c40353654.zip cpython-c3ce0e53ad81263b20ef660722a4e65c40353654.tar.gz cpython-c3ce0e53ad81263b20ef660722a4e65c40353654.tar.bz2 |
Silence -3 warnings in pstats: a dict.has_key() usage and backport solution to
move from list.sort(cmp=) to key=.
Diffstat (limited to 'Lib/pstats.py')
-rw-r--r-- | Lib/pstats.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/pstats.py b/Lib/pstats.py index adaac5c..a6844fb 100644 --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -140,7 +140,7 @@ class Stats: 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 @@ class Stats: 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 @@ class TupleComp: 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) |