[pypy-svn] r11885 - in pypy/dist/pypy: interpreter objspace/std
arigo at codespeak.net
arigo at codespeak.net
Tue May 3 20:49:16 CEST 2005
Author: arigo
Date: Tue May 3 20:49:15 2005
New Revision: 11885
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/function.py
pypy/dist/pypy/interpreter/typedef.py
pypy/dist/pypy/objspace/std/objecttype.py
Log:
__repr__ for functions and built-in functions.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Tue May 3 20:49:15 2005
@@ -3,6 +3,7 @@
from pypy.interpreter.miscutils import getthreadlocals
from pypy.interpreter.argument import Arguments
from pypy.tool.cache import Cache
+from pypy.tool.rarithmetic import r_uint
__all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'BaseWrappable',
'W_Root']
@@ -34,7 +35,11 @@
if e.match(space, space.w_TypeError) or e.match(space, space.w_AttributeError):
return default
raise
-
+
+ def getrepr(self, space, info):
+ id = space.int_w(space.id(self)) # xxx ids could be long
+ id = r_uint(id) # XXX what about sizeof(void*) > sizeof(long) !!
+ return space.wrap("<%s at 0x%x>" % (info, id))
class BaseWrappable(W_Root):
"""A subclass of BaseWrappable is an internal, interpreter-level class
Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py (original)
+++ pypy/dist/pypy/interpreter/function.py Tue May 3 20:49:15 2005
@@ -104,6 +104,9 @@
def descr_function_call(self, __args__):
return self.call_args(__args__)
+ def descr_function_repr(self):
+ return self.getrepr(self.space, 'function %s' % (self.name,))
+
def fget_func_defaults(space, self):
values_w = self.defs_w
if not values_w:
@@ -282,3 +285,6 @@
bltin = space.allocate_instance(BuiltinFunction, w_subtype)
bltin.__init__(func)
return space.wrap(bltin)
+
+ def descr_function_repr(self):
+ return self.space.wrap('<built-in function %s>' % (self.name,))
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Tue May 3 20:49:15 2005
@@ -396,6 +396,7 @@
__call__ = interp2app(Function.descr_function_call,
unwrap_spec=['self', Arguments]),
__get__ = interp2app(Function.descr_function_get),
+ __repr__ = interp2app(Function.descr_function_repr),
func_code = getset_func_code,
func_doc = getset_func_doc,
func_name = interp_attrproperty('name', cls=Function),
@@ -434,7 +435,8 @@
BuiltinFunction.typedef = TypeDef("builtin_function",**Function.typedef.rawdict)
BuiltinFunction.typedef.rawdict.update({
'__new__': interp2app(BuiltinFunction.descr_method__new__.im_func),
- '__self__': GetSetProperty(always_none, cls=BuiltinFunction)
+ '__self__': GetSetProperty(always_none, cls=BuiltinFunction),
+ '__repr__': interp2app(BuiltinFunction.descr_function_repr),
})
del BuiltinFunction.typedef.rawdict['__get__']
Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py (original)
+++ pypy/dist/pypy/objspace/std/objecttype.py Tue May 3 20:49:15 2005
@@ -3,15 +3,12 @@
from pypy.objspace.std.stdtypedef import *
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.objspace import StdObjSpace
-from pypy.tool.rarithmetic import r_uint
def descr__repr__(space, w_obj):
w = space.wrap
classname = space.str_w(space.getattr(space.type(w_obj), w("__name__")))
- id = space.int_w(space.id(w_obj))# xxx ids could be long
- id = r_uint(id) # XXX what about sizeof(void*) > sizeof(long) !!
- return w("<%s object at 0x%x>" % (classname, id))
+ return w_obj.getrepr(space, '%s object' % (classname,))
def descr__str__(space, w_obj):
return space.repr(w_obj)
More information about the Pypy-commit
mailing list