[pypy-svn] r12299 - in pypy/dist/pypy/interpreter: . test

arigo at codespeak.net arigo at codespeak.net
Sun May 15 17:16:50 CEST 2005


Author: arigo
Date: Sun May 15 17:16:50 2005
New Revision: 12299

Modified:
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/test/test_function.py
Log:
The repr of method objects need to use w_class.getname() instead of read
w_class.name directly, because we have no control over what w_class can be
(e.g. old-style classes don't have such an interp-level attribute).

Use getrepr() instead of uid().


Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Sun May 15 17:16:50 2005
@@ -11,7 +11,6 @@
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.eval import Code
 from pypy.interpreter.gateway import NoneNotWrapped
-from pypy.tool.uid import uid 
 
 class Function(Wrappable):
     """A function is a code object captured with some environment:
@@ -251,13 +250,13 @@
             w_class = space.type(self.w_instance) 
         else: 
             w_class = self.w_class 
-        typename = w_class.name 
+        typename = w_class.getname(self.space, '?')
         if self.w_instance is None: 
             s = "<method '%s' of '%s' objects>" %(name, typename) 
+            return space.wrap(s)
         else:
-            s = "<method %s of %s object at 0x%x>" %(
-                name, typename, uid(self.w_instance))
-        return space.wrap(s) 
+            info = "method %s of %s object" % (name, typename)
+            return self.w_instance.getrepr(self.space, info)
 
     def descr_method_getattribute(self, w_attr):
         space = self.space

Modified: pypy/dist/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_function.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_function.py	Sun May 15 17:16:50 2005
@@ -197,10 +197,17 @@
         assert repr(dict.items) == "<method 'items' of 'dict' objects>"
         class A(object): 
             def f(self): 
-                pass 
+                pass
         assert repr(A.f) == "<method 'f' of 'A' objects>"
         assert repr(A().f).startswith("<method f of A object at") 
         assert repr(A.f.__get__(None)).startswith("<method f")
+        class B:
+            __metaclass__ = _classobj
+            def f(self):
+                pass
+        assert repr(B.f) == "<method 'f' of 'B' objects>"
+        assert repr(B().f).startswith("<method f of B object at") 
+        assert repr(B.f.__get__(None)).startswith("<method f")
 
 class TestMethod: 
     def setup_method(self, method):



More information about the Pypy-commit mailing list