[pypy-svn] r54347 - in pypy/dist/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Fri May 2 20:05:02 CEST 2008
Author: arigo
Date: Fri May 2 20:05:02 2008
New Revision: 54347
Modified:
pypy/dist/pypy/objspace/std/objecttype.py
pypy/dist/pypy/objspace/std/test/test_userobject.py
Log:
Fix object.__repr__() to show the class' module name,
as in CPython.
Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py (original)
+++ pypy/dist/pypy/objspace/std/objecttype.py Fri May 2 20:05:02 2008
@@ -9,7 +9,17 @@
def descr__repr__(space, w_obj):
w = space.wrap
- classname = space.str_w(space.getattr(space.type(w_obj), w("__name__")))
+ w_type = space.type(w_obj)
+ classname = w_type.getname(space, '?')
+ w_module = w_type.lookup("__module__")
+ if w_module is not None:
+ try:
+ modulename = space.str_w(w_module)
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
+ else:
+ classname = '%s.%s' % (modulename, classname)
return w_obj.getrepr(space, '%s object' % (classname,))
def descr__str__(space, w_obj):
Modified: pypy/dist/pypy/objspace/std/test/test_userobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_userobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_userobject.py Fri May 2 20:05:02 2008
@@ -200,6 +200,13 @@
assert myint(3) - 5 == -2
assert 5 - myint(3) == 'rsub'
+ def test_repr(self):
+ class Foo(object):
+ pass
+ Foo.__module__ = 'a.b.c'
+ s = repr(Foo())
+ assert s.startswith('<a.b.c.Foo object at ')
+
class AppTestWithMultiMethodVersion2(AppTestUserObject):
OPTIONS = {} # for test_builtinshortcut.py
More information about the Pypy-commit
mailing list