[pypy-svn] r75810 - in pypy/branch/fast-forward/pypy/objspace/std: . test
benjamin at codespeak.net
benjamin at codespeak.net
Sat Jul 3 01:34:21 CEST 2010
Author: benjamin
Date: Sat Jul 3 01:34:19 2010
New Revision: 75810
Modified:
pypy/branch/fast-forward/pypy/objspace/std/floattype.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
Log:
creating float subclasses is a bit different
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 Sat Jul 3 01:34:19 2010
@@ -17,13 +17,15 @@
def descr__new__(space, w_floattype, w_x=0.0):
from pypy.objspace.std.floatobject import W_FloatObject
w_value = w_x # 'x' is the keyword argument name in CPython
- w_special = space.lookup(w_x, "__float__")
+ w_special = space.lookup(w_value, "__float__")
if w_special is not None:
- w_obj = space.get_and_call_function(w_special, w_x)
+ w_obj = space.get_and_call_function(w_special, w_value)
if not space.isinstance_w(w_obj, space.w_float):
raise OperationError(space.w_TypeError,
space.wrap("__float__ returned non-float"))
- return w_obj
+ if space.is_w(w_floattype, space.gettypeobject(float_typedef)):
+ return w_obj
+ value = space.float_w(w_obj)
elif space.is_true(space.isinstance(w_value, space.w_str)):
strvalue = space.str_w(w_value)
try:
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 Sat Jul 3 01:34:19 2010
@@ -132,6 +132,12 @@
raises(OverflowError, float('-inf').as_integer_ratio)
raises(ValueError, float('nan').as_integer_ratio)
+ def test_float_conversion(self):
+ class X(float):
+ def __float__(self):
+ return 42.
+ assert float(X()) == 42.
+
def test_round(self):
assert 1.0 == round(1.0)
assert 1.0 == round(1.1)
More information about the Pypy-commit
mailing list