[pypy-commit] pypy default: Test and fix for 'methodcaller(..., self=...)'

arigo pypy.commits at gmail.com
Sun Nov 20 10:48:43 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r88493:030861c2e0a2
Date: 2016-11-20 16:48 +0100
http://bitbucket.org/pypy/pypy/changeset/030861c2e0a2/

Log:	Test and fix for 'methodcaller(..., self=...)'

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
@@ -130,9 +130,12 @@
 
 
 class methodcaller(object):
-    def __init__(self, method_name, *args, **kwargs):
+    def __init__(*args, **kwargs):
+        if len(args) < 2:
+            raise TypeError("methodcaller() called with not enough arguments")
+        self, method_name = args[:2]
         self._method_name = method_name
-        self._args = args
+        self._args = args[2:]
         self._kwargs = kwargs
 
     def __call__(self, obj):
diff --git a/pypy/module/operator/test/test_operator.py b/pypy/module/operator/test/test_operator.py
--- a/pypy/module/operator/test/test_operator.py
+++ b/pypy/module/operator/test/test_operator.py
@@ -244,6 +244,13 @@
         assert methodcaller("method", 4, 5)(x) == (4, 5)
         assert methodcaller("method", 4, arg2=42)(x) == (4, 42)
 
+    def test_methodcaller_self(self):
+        from operator import methodcaller
+        class X:
+            def method(myself, self):
+                return self * 6
+        assert methodcaller("method", self=7)(X()) == 42
+
     def test_index(self):
         import operator
         assert operator.index(42) == 42


More information about the pypy-commit mailing list