diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-25 13:55:54 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-25 13:55:54 (GMT) |
commit | 8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab (patch) | |
tree | 65436ba5d34417e9e89804d3b1c2c324edfb2f4e /Lib/test/test_float.py | |
parent | 80767a38c74318acbd6fc4bfe228a1d0c0556221 (diff) | |
download | cpython-8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab.zip cpython-8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab.tar.gz cpython-8d30ad7c8ad5df59be8a65c8f8dab0d13be00dab.tar.bz2 |
Issue #24731: Fixed crash on converting objects with special methods
__str__, __trunc__, and __float__ returning instances of subclasses of
str, long, and float to subclasses of str, long, and float correspondingly.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r-- | Lib/test/test_float.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 4224306..4ec894c 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -27,6 +27,12 @@ requires_IEEE_754 = unittest.skipUnless(have_getformat and test_dir = os.path.dirname(__file__) or os.curdir format_testfile = os.path.join(test_dir, 'formatfloat_testcases.txt') +class FloatSubclass(float): + pass + +class OtherFloatSubclass(float): + pass + class GeneralFloatCases(unittest.TestCase): def test_float(self): @@ -200,6 +206,15 @@ class GeneralFloatCases(unittest.TestCase): return "" self.assertRaises(TypeError, time.sleep, Foo5()) + # Issue #24731 + class F: + def __float__(self): + return OtherFloatSubclass(42.) + self.assertAlmostEqual(float(F()), 42.) + self.assertIs(type(float(F())), OtherFloatSubclass) + self.assertAlmostEqual(FloatSubclass(F()), 42.) + self.assertIs(type(FloatSubclass(F())), FloatSubclass) + def test_is_integer(self): self.assertFalse((1.1).is_integer()) self.assertTrue((1.).is_integer()) |