[pypy-svn] r11997 - pypy/dist/pypy/interpreter

arigo at codespeak.net arigo at codespeak.net
Fri May 6 00:49:40 CEST 2005


Author: arigo
Date: Fri May  6 00:49:40 2005
New Revision: 11997

Modified:
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/typedef.py
Log:
Fixed method.__get__().  Done by making function.__get__ really generic,
as it doesn't really depend on the fact that 'self' is a function.



Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Fri May  6 00:49:40 2005
@@ -88,19 +88,6 @@
         Function.__init__(func, space, code, w_globals, defs_w, closure, name)
         return space.wrap(func)
 
-    def descr_function_get(self, w_obj, w_cls=None):
-        space = self.space
-        wrap = space.wrap
-        asking_for_bound = (w_cls == space.w_None or
-                      not space.is_true(space.is_(w_obj, space.w_None)) or
-                      space.is_true(space.is_(w_cls, space.type(space.w_None))))
-        if asking_for_bound:
-            #if w_cls == space.w_None:
-            #    w_cls = space.type(w_obj)
-            return wrap(Method(space, wrap(self), w_obj, w_cls))
-        else:
-            return wrap(Method(space, wrap(self), None, w_cls))
-
     def descr_function_call(self, __args__):
         return self.call_args(__args__)
 
@@ -162,6 +149,20 @@
             w_res = space.w_None
         return w_res
 
+def descr_function_get(space, w_function, w_obj, w_cls=None):
+    # this is not defined as a method on Function because it's generally
+    # useful logic: w_function can be any callable.  It is used by Method too.
+    asking_for_bound = (space.is_w(w_cls, space.w_None) or
+                        not space.is_w(w_obj, space.w_None) or
+                        space.is_w(w_cls, space.type(space.w_None)))
+    if asking_for_bound:
+        #if w_cls == space.w_None:
+        #    w_cls = space.type(w_obj)
+        return space.wrap(Method(space, w_function, w_obj, w_cls))
+    else:
+        return space.wrap(Method(space, w_function, None, w_cls))
+
+
 def _getclass(space, w_obj):
     try:
         return space.abstract_getclass(w_obj)
@@ -191,7 +192,7 @@
             pre = "bound"
         else:
             pre = "unbound"
-        return "%s method %s" % (pre, self.w_function.name)
+        return "%s method %s" % (pre, self.w_function.getname(self.space, '?'))
 
     def call_args(self, args):
         space = self.space
@@ -233,8 +234,9 @@
             if (w_cls is not None and
                 not space.is_w(w_cls, space.w_None) and
                 not space.is_true(space.abstract_issubclass(w_cls, self.w_class))):
-                return space.wrap(self)   # subclass test failed
-            return space.get(self.w_function, w_obj, w_cls)
+                return space.wrap(self)    # subclass test failed
+            else:
+                return descr_function_get(space, self.w_function, w_obj, w_cls)
 
     def descr_method_call(self, __args__):
         return self.call_args(__args__)

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Fri May  6 00:49:40 2005
@@ -280,7 +280,7 @@
 from pypy.interpreter.pyframe import PyFrame, ControlFlowException
 from pypy.interpreter.module import Module
 from pypy.interpreter.function import Function, Method, StaticMethod
-from pypy.interpreter.function import BuiltinFunction
+from pypy.interpreter.function import BuiltinFunction, descr_function_get
 from pypy.interpreter.pytraceback import PyTraceback
 from pypy.interpreter.generator import GeneratorIterator 
 from pypy.interpreter.nestedscope import Cell
@@ -405,7 +405,7 @@
     __new__ = interp2app(Function.descr_method__new__.im_func),                           
     __call__ = interp2app(Function.descr_function_call,
                           unwrap_spec=['self', Arguments]),
-    __get__ = interp2app(Function.descr_function_get),
+    __get__ = interp2app(descr_function_get),
     __repr__ = interp2app(Function.descr_function_repr),
     func_code = getset_func_code, 
     func_doc = getset_func_doc,



More information about the Pypy-commit mailing list