[pypy-svn] r75805 - in pypy/branch/fast-forward/pypy/objspace/std: . test
benjamin at codespeak.net
benjamin at codespeak.net
Sat Jul 3 00:25:51 CEST 2010
Author: benjamin
Date: Sat Jul 3 00:25:50 2010
New Revision: 75805
Modified:
pypy/branch/fast-forward/pypy/objspace/std/floattype.py
pypy/branch/fast-forward/pypy/objspace/std/test/test_floatobject.py
Log:
always ask for __float__ first
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 00:25:50 2010
@@ -16,7 +16,14 @@
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
- if space.is_true(space.isinstance(w_value, space.w_str)):
+ w_special = space.lookup(w_x, "__float__")
+ if w_special is not None:
+ w_obj = space.get_and_call_function(w_special, w_x)
+ if not space.isinstance_w(w_obj, space.w_float):
+ raise OperationError(space.w_TypeError,
+ space.wrap("__float__ returned non-float"))
+ return w_obj
+ elif space.is_true(space.isinstance(w_value, space.w_str)):
strvalue = space.str_w(w_value)
try:
value = interp_string_to_float(space, strvalue)
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 00:25:50 2010
@@ -109,6 +109,10 @@
def test_float_unicode(self):
# u00A0 and u2000 are some kind of spaces
assert 42.75 == float(unichr(0x00A0)+unicode("42.75")+unichr(0x2000))
+ class FloatUnicode(unicode):
+ def __float__(self):
+ return float(unicode(self)) + 1
+ assert float(FloatUnicode("8")) == 9.0
def test_float_long(self):
assert 42.0 == float(42L)
More information about the Pypy-commit
mailing list