[pypy-commit] pypy default: Similarly, rewrite operator.itemgetter().

arigo noreply at buildbot.pypy.org
Fri Jun 17 14:19:30 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r44986:b4a0b67f2b26
Date: 2011-06-17 14:22 +0200
http://bitbucket.org/pypy/pypy/changeset/b4a0b67f2b26/

Log:	Similarly, rewrite operator.itemgetter().

diff --git a/pypy/module/operator/app_operator.py b/pypy/module/operator/app_operator.py
--- a/pypy/module/operator/app_operator.py
+++ b/pypy/module/operator/app_operator.py
@@ -105,20 +105,16 @@
     return make_getter(attr[last:], getter)
 
 
-class itemgetter(object):
+def itemgetter(item, *items):
+    if items:
+        list_of_indices = [item] + list(items)
+        def getter(obj):
+            return tuple([obj[i] for i in list_of_indices])
+    else:
+        def getter(obj):
+            return obj[item]
+    return builtinify(getter)
 
-    def __init__(self, item, *args):
-        self.items = args
-        self.item = item
-
-    def __call__(self, obj):
-        result = obj[self.item]
-
-        if self.items:
-            list = [result] + [obj[item] for item in self.items]
-            return tuple(list)
-
-        return result
 
 class methodcaller(object):
 


More information about the pypy-commit mailing list