summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-25 13:52:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-25 13:52:04 (GMT)
commitf9afda57ad7d0394531982b2c9de8301c5a54e45 (patch)
tree8a09bb1aa816b4daf6777e630333dfece309cdb5 /Lib/test/test_float.py
parentc5f3b4285a8f3f90305d777a88a856a623c22cb1 (diff)
parent15095800a381a396cbc077cb5320203a8feae51a (diff)
downloadcpython-f9afda57ad7d0394531982b2c9de8301c5a54e45.zip
cpython-f9afda57ad7d0394531982b2c9de8301c5a54e45.tar.gz
cpython-f9afda57ad7d0394531982b2c9de8301c5a54e45.tar.bz2
Issue #24731: Fixed crash on converting objects with special methods
__bytes__, __trunc__, and __float__ returning instances of subclasses of bytes, int, and float to subclasses of bytes, int, and float correspondingly.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 723beb3..48f7a70 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -25,6 +25,12 @@ requires_setformat = unittest.skipUnless(hasattr(float, "__setformat__"),
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):
@@ -167,6 +173,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())