summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-04-15 21:26:36 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-04-15 21:26:36 (GMT)
commit99d36f15639b9efa9ad110005605ae28ca65e829 (patch)
treefd2a8fa4f81dd7fba0641f708c594b6e962a3100 /Lib/test/test_float.py
parent5c9914899bb220eefceb4fad685694bbc04a905c (diff)
downloadcpython-99d36f15639b9efa9ad110005605ae28ca65e829.zip
cpython-99d36f15639b9efa9ad110005605ae28ca65e829.tar.gz
cpython-99d36f15639b9efa9ad110005605ae28ca65e829.tar.bz2
call __float__ on str subclasses #5759
tests by R. David Murray
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 2b6bd78..0b1ae96 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -82,11 +82,23 @@ class GeneralFloatCases(unittest.TestCase):
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 [