diff options
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r-- | Lib/test/test_float.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 2d3b357..123a69d 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -78,11 +78,18 @@ 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 + 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(FooStr('8')), 9.) def test_floatasratio(self): for f, ratio in [ |