[pypy-svn] r55736 - in pypy/dist/pypy/interpreter: . test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Jun 10 14:54:38 CEST 2008
Author: antocuni
Date: Tue Jun 10 14:54:35 2008
New Revision: 55736
Modified:
pypy/dist/pypy/interpreter/module.py
pypy/dist/pypy/interpreter/test/test_module.py
pypy/dist/pypy/interpreter/typedef.py
Log:
try to make the repr of module objects more similar to cpython's
Modified: pypy/dist/pypy/interpreter/module.py
==============================================================================
--- pypy/dist/pypy/interpreter/module.py (original)
+++ pypy/dist/pypy/interpreter/module.py Tue Jun 10 14:54:35 2008
@@ -66,3 +66,11 @@
w_import = space.builtin.get('__import__')
return space.newtuple([w_import, space.newtuple([w_name])])
+ def descr_module__repr__(self, space):
+ from pypy.interpreter.mixedmodule import MixedModule
+ name = space.str_w(space.repr(self.w_name))
+ if isinstance(self, MixedModule):
+ return space.wrap("<module %s (built-in)>" % name)
+ w___file__ = space.getattr(self, space.wrap('__file__'))
+ __file__ = space.str_w(space.repr(w___file__))
+ return space.wrap("<module %s from %s>" % (name, __file__))
Modified: pypy/dist/pypy/interpreter/test/test_module.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_module.py (original)
+++ pypy/dist/pypy/interpreter/test/test_module.py Tue Jun 10 14:54:35 2008
@@ -52,3 +52,14 @@
skip("need PyPy for sys.__file__ checking")
assert sys.__file__
assert os.path.basename(sys.__file__) == 'sys'
+
+ def test_repr(self):
+ import sys
+ r = repr(sys)
+ assert r == "<module 'sys' (built-in)>"
+
+ import _exceptions # known to be in pypy/lib
+ r = repr(_exceptions)
+ assert r.startswith("<module '_exceptions' from ") and \
+ 'pypy/lib/_exceptions.py' in r and \
+ r.endswith('>')
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Tue Jun 10 14:54:35 2008
@@ -704,6 +704,8 @@
__new__ = interp2app(Module.descr_module__new__.im_func,
unwrap_spec=[ObjSpace, W_Root, Arguments]),
__init__ = interp2app(Module.descr_module__init__),
+ __repr__ = interp2app(Module.descr_module__repr__,
+ unwrap_spec=['self', ObjSpace]),
__reduce__ = interp2app(Module.descr__reduce__,
unwrap_spec=['self', ObjSpace]),
__dict__ = GetSetProperty(descr_get_dict, cls=Module), # module dictionaries are readonly attributes
More information about the Pypy-commit
mailing list