From: Raymond Hettinger Date: Mon, 1 Dec 2003 20:12:15 +0000 (+0000) Subject: Apply extract functions instead of lambda. X-Git-Tag: v2.4a1~1181 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3375fc5a3b3a6f53fff446bfb28147fba4cc2e3a;p=thirdparty%2FPython%2Fcpython.git Apply extract functions instead of lambda. --- diff --git a/Lib/inspect.py b/Lib/inspect.py index 4874904076ee..0e0e9e5078f7 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -29,6 +29,7 @@ __author__ = 'Ka-Ping Yee ' __date__ = '1 Jan 2001' import sys, os, types, string, re, dis, imp, tokenize, linecache +from operator import attrgetter # ----------------------------------------------------------- type-checking def ismodule(object): @@ -553,7 +554,7 @@ def getsource(object): def walktree(classes, children, parent): """Recursive helper function for getclasstree().""" results = [] - classes.sort(key=lambda c: c.__name__) + classes.sort(key=attrgetter('__name__')) for c in classes: results.append((c, c.__bases__)) if c in children: diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py index 26cc0ce0dade..6674b71ff094 100644 --- a/Lib/pyclbr.py +++ b/Lib/pyclbr.py @@ -43,6 +43,7 @@ import sys import imp import tokenize # Python tokenizer from token import NAME, DEDENT, NEWLINE +from operator import itemgetter __all__ = ["readmodule", "readmodule_ex", "Class", "Function"] @@ -326,8 +327,7 @@ def _main(): for obj in objs: if isinstance(obj, Class): print "class", obj.name, obj.super, obj.lineno - methods = obj.methods.items() - methods.sort(lambda a, b: cmp(a[1], b[1])) + methods = list.sorted(obj.methods.iteritems(), key=itemgetter(1)) for name, lineno in methods: if name != "__path__": print " def", name, lineno