[pypy-svn] r75751 - in pypy/branch/fast-forward/pypy/objspace/std: . test

benjamin at codespeak.net benjamin at codespeak.net
Fri Jul 2 01:42:43 CEST 2010


Author: benjamin
Date: Fri Jul  2 01:42:41 2010
New Revision: 75751

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/floattype.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
Log:
fake float.__getformat__

Modified: pypy/branch/fast-forward/pypy/objspace/std/floattype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/floattype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/floattype.py	Fri Jul  2 01:42:41 2010
@@ -1,4 +1,5 @@
 from pypy.interpreter import gateway
+from pypy.interpreter.baseobjspace import ObjSpace, W_Root
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.strutil import ParseStringError
@@ -35,6 +36,18 @@
     W_FloatObject.__init__(w_obj, value)
     return w_obj
 
+
+_float_format = float.__getformat__("float")
+_double_format = float.__getformat__("double")
+def descr___getformat__(space, w_cls, kind):
+    if kind == "float":
+        return space.wrap(_float_format)
+    elif kind == "double":
+        return space.wrap(_double_format)
+    raise OperationError(space.w_ValueError,
+                         space.wrap("only float and double are valid"))
+
+
 # ____________________________________________________________
 
 float_typedef = StdTypeDef("float",
@@ -42,4 +55,7 @@
 
 Convert a string or number to a floating point number, if possible.''',
     __new__ = gateway.interp2app(descr__new__),
+    __getformat__ = gateway.interp2app(descr___getformat__,
+                                       unwrap_spec=[ObjSpace, W_Root, str],
+                                       as_classmethod=True),
     )

Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py	Fri Jul  2 01:42:41 2010
@@ -317,6 +317,11 @@
                 assert not (nan <  x)
                 assert not (nan >  x)
 
+    def test___getformat__(self):
+        float.__getformat__("float")
+        float.__getformat__("double")
+        raises(ValueError, float.__getformat__, "random")
+
     def test_multimethod_slice(self):
         assert 5 .__add__(3.14) is NotImplemented
         assert 3.25 .__add__(5) == 8.25



More information about the Pypy-commit mailing list