[pypy-svn] r10946 - in pypy/dist/pypy/objspace/std: . test
pedronis at codespeak.net
pedronis at codespeak.net
Thu Apr 21 00:54:48 CEST 2005
Author: pedronis
Date: Thu Apr 21 00:54:48 2005
New Revision: 10946
Modified:
pypy/dist/pypy/objspace/std/floatobject.py
pypy/dist/pypy/objspace/std/floattype.py
pypy/dist/pypy/objspace/std/intobject.py
pypy/dist/pypy/objspace/std/inttype.py
pypy/dist/pypy/objspace/std/longobject.py
pypy/dist/pypy/objspace/std/longtype.py
pypy/dist/pypy/objspace/std/objspace.py
pypy/dist/pypy/objspace/std/stringobject.py
pypy/dist/pypy/objspace/std/stringtype.py
pypy/dist/pypy/objspace/std/test/test_longobject.py
pypy/dist/pypy/objspace/std/tupleobject.py
pypy/dist/pypy/objspace/std/tupletype.py
Log:
move implementions of __getnewargs__ to multimethods, this makes sense in term of possible multiple internal impls,
and more directly now gives us type precision for the argument.
Modified: pypy/dist/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/floatobject.py (original)
+++ pypy/dist/pypy/objspace/std/floatobject.py Thu Apr 21 00:54:48 2005
@@ -245,4 +245,7 @@
StdObjSpace.coerce.register(float_coerce, W_FloatObject)
"""
+def getnewargs__Float(space, w_float):
+ return space.newtuple([W_FloatObject(space, w_float.floatval)])
+
register_all(vars())
Modified: pypy/dist/pypy/objspace/std/floattype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/floattype.py (original)
+++ pypy/dist/pypy/objspace/std/floattype.py Thu Apr 21 00:54:48 2005
@@ -19,13 +19,8 @@
w_obj.__init__(space, value)
return w_obj
-def descr__getnewargs__(space, w_obj):
- from pypy.objspace.std.floatobject import W_FloatObject
- return space.newtuple([W_FloatObject(space, w_obj.floatval)])
-
# ____________________________________________________________
float_typedef = StdTypeDef("float",
__new__ = newmethod(descr__new__),
- __getnewargs__ = newmethod(descr__getnewargs__),
)
Modified: pypy/dist/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/intobject.py (original)
+++ pypy/dist/pypy/objspace/std/intobject.py Thu Apr 21 00:54:48 2005
@@ -442,4 +442,8 @@
ret = "0x%lx" % x
return space.wrap(ret)
+def getnewargs__Int(space, w_int1):
+ return space.newtuple([W_IntObject(space, w_int1.intval)])
+
+
register_all(vars())
Modified: pypy/dist/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/inttype.py (original)
+++ pypy/dist/pypy/objspace/std/inttype.py Thu Apr 21 00:54:48 2005
@@ -67,13 +67,8 @@
w_obj.__init__(space, value)
return w_obj
-def descr__getnewargs__(space, w_obj):
- from pypy.objspace.std.intobject import W_IntObject
- return space.newtuple([W_IntObject(space, w_obj.intval)])
-
# ____________________________________________________________
int_typedef = StdTypeDef("int",
__new__ = newmethod(descr__new__),
- __getnewargs__ = newmethod(descr__getnewargs__),
)
Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py (original)
+++ pypy/dist/pypy/objspace/std/longobject.py Thu Apr 21 00:54:48 2005
@@ -479,6 +479,9 @@
x = w_long1.longval()
return space.wrap(hex(x))
+def getnewargs__Long(space, w_long1):
+ return space.newtuple([W_LongObject(space, w_long1.digits, w_long1.sign)])
+
register_all(vars())
Modified: pypy/dist/pypy/objspace/std/longtype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longtype.py (original)
+++ pypy/dist/pypy/objspace/std/longtype.py Thu Apr 21 00:54:48 2005
@@ -53,15 +53,10 @@
w_obj.__init__(space, *args_from_long(value))
return w_obj
-def descr__getnewargs__(space, w_obj):
- from pypy.objspace.std.longobject import W_LongObject
- return space.newtuple([W_LongObject(space, w_obj.digits, w_obj.sign)])
-
# ____________________________________________________________
long_typedef = StdTypeDef("long",
__new__ = newmethod(descr__new__),
- __getnewargs__ = newmethod(descr__getnewargs__),
)
# hack to allow automatic int to long conversion: the int.__xyz__ methods
# will fall back to their long.__xyz__ counterparts if they fail
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Thu Apr 21 00:54:48 2005
@@ -310,6 +310,7 @@
"Container for multimethods."
call = MultiMethod('call', 1, ['__call__'], general__args__=True)
init = MultiMethod('__init__', 1, general__args__=True)
+ getnewargs = MultiMethod('__getnewargs__', 1)
# special visible multimethods
int_w = MultiMethod('int_w', 1, []) # returns an unwrapped int
str_w = MultiMethod('str_w', 1, []) # returns an unwrapped string
Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py (original)
+++ pypy/dist/pypy/objspace/std/stringobject.py Thu Apr 21 00:54:48 2005
@@ -969,6 +969,10 @@
space.wrap("ord() expected a character, but string "
"of length %d found"%(len(w_str._value),)))
return space.wrap(ord(u_str))
+
+def getnewargs__String(space, w_str):
+ return space.newtuple([W_StringObject(space, w_str._value)])
+
app = gateway.applevel(r'''
import codecs
Modified: pypy/dist/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringtype.py (original)
+++ pypy/dist/pypy/objspace/std/stringtype.py Thu Apr 21 00:54:48 2005
@@ -49,14 +49,9 @@
w_obj.__init__(space, value)
return w_obj
-def descr__getnewargs__(space, w_obj):
- from pypy.objspace.std.stringobject import W_StringObject
- return space.newtuple([W_StringObject(space, w_obj._value)])
-
# ____________________________________________________________
str_typedef = StdTypeDef("str", basestring_typedef,
__new__ = newmethod(descr__new__),
- __getnewargs__ = newmethod(descr__getnewargs__),
)
str_typedef.registermethods(globals())
Modified: pypy/dist/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_longobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_longobject.py Thu Apr 21 00:54:48 2005
@@ -218,3 +218,4 @@
def test_getnewargs(self):
assert 0L .__getnewargs__() == (0L,)
+ assert (-1L) .__getnewargs__() == (-1L,)
Modified: pypy/dist/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/tupleobject.py (original)
+++ pypy/dist/pypy/objspace/std/tupleobject.py Thu Apr 21 00:54:48 2005
@@ -135,4 +135,8 @@
x += 97531
return space.wrap(intmask(x))
+def getnewargs__Tuple(space, w_tuple):
+ return space.newtuple([W_TupleObject(space, w_tuple.wrappeditems)])
+
+
register_all(vars())
Modified: pypy/dist/pypy/objspace/std/tupletype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/tupletype.py (original)
+++ pypy/dist/pypy/objspace/std/tupletype.py Thu Apr 21 00:54:48 2005
@@ -14,13 +14,8 @@
w_obj.__init__(space, tuple_w)
return w_obj
-def descr__getnewargs__(space, w_obj):
- from pypy.objspace.std.tupleobject import W_TupleObject
- return space.newtuple([W_TupleObject(space, w_obj.wrappeditems)])
-
# ____________________________________________________________
tuple_typedef = StdTypeDef("tuple",
__new__ = newmethod(descr__new__),
- __getnewargs__ = newmethod(descr__getnewargs__),
)
More information about the Pypy-commit
mailing list