[Python-checkins] r71630 - in python/branches/release26-maint: Lib/test/test_float.py Misc/NEWS Objects/floatobject.c
benjamin.peterson
python-checkins at python.org
Wed Apr 15 23:46:14 CEST 2009
Author: benjamin.peterson
Date: Wed Apr 15 23:46:14 2009
New Revision: 71630
Log:
Merged revisions 71627 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r71627 | benjamin.peterson | 2009-04-15 16:26:36 -0500 (Wed, 15 Apr 2009) | 4 lines
call __float__ on str subclasses #5759
tests by R. David Murray
........
Modified:
python/branches/release26-maint/ (props changed)
python/branches/release26-maint/Lib/test/test_float.py
python/branches/release26-maint/Misc/NEWS
python/branches/release26-maint/Objects/floatobject.c
Modified: python/branches/release26-maint/Lib/test/test_float.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_float.py (original)
+++ python/branches/release26-maint/Lib/test/test_float.py Wed Apr 15 23:46:14 2009
@@ -82,11 +82,23 @@
def __float__(self):
return 42
+ # Issue 5759: __float__ not called on str subclasses (though it is on
+ # unicode subclasses).
+ class FooStr(str):
+ def __float__(self):
+ return float(str(self)) + 1
+
+ class FooUnicode(unicode):
+ def __float__(self):
+ return float(unicode(self)) + 1
+
self.assertAlmostEqual(float(Foo0()), 42.)
self.assertAlmostEqual(float(Foo1()), 42.)
self.assertAlmostEqual(float(Foo2()), 42.)
self.assertAlmostEqual(float(Foo3(21)), 42.)
self.assertRaises(TypeError, float, Foo4(42))
+ self.assertAlmostEqual(float(FooUnicode('8')), 9.)
+ self.assertAlmostEqual(float(FooStr('8')), 9.)
def test_floatasratio(self):
for f, ratio in [
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS (original)
+++ python/branches/release26-maint/Misc/NEWS Wed Apr 15 23:46:14 2009
@@ -4,10 +4,15 @@
(editors: check NEWS.help for information about editing NEWS using ReST.)
-What's New in Python 2.6.2
+What's New in Python 2.6.3
==========================
-*Release date: 14-Apr-2009*
+*Release date: XX-XX-XXX*
+
+Core and Builtins
+-----------------
+
+- Issue #5759: float() didn't call __float__ on str subclasses.
What's New in Python 2.6.2 rc 1
Modified: python/branches/release26-maint/Objects/floatobject.c
==============================================================================
--- python/branches/release26-maint/Objects/floatobject.c (original)
+++ python/branches/release26-maint/Objects/floatobject.c Wed Apr 15 23:46:14 2009
@@ -1630,7 +1630,9 @@
return float_subtype_new(type, args, kwds); /* Wimp out */
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x))
return NULL;
- if (PyString_Check(x))
+ /* If it's a string, but not a string subclass, use
+ PyFloat_FromString. */
+ if (PyString_CheckExact(x))
return PyFloat_FromString(x, NULL);
return PyNumber_Float(x);
}
More information about the Python-checkins
mailing list