summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-12 07:39:32 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-12 07:39:32 (GMT)
commit1f364438adf1bcdc89a51af9af526ed9d7b7996d (patch)
tree2d620f18e63ff8703f4da17d98d0467a40a3c507 /Lib/test/test_float.py
parent5787ef621a76dfe225308f0001d60e5e46e9a55f (diff)
parentea36c941a1b2ad6582a35bc42aa70da9600d2841 (diff)
downloadcpython-1f364438adf1bcdc89a51af9af526ed9d7b7996d.zip
cpython-1f364438adf1bcdc89a51af9af526ed9d7b7996d.tar.gz
cpython-1f364438adf1bcdc89a51af9af526ed9d7b7996d.tar.bz2
Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 2e187ac..427f044 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -1354,6 +1354,24 @@ class HexFloatTestCase(unittest.TestCase):
else:
self.identical(x, fromHex(toHex(x)))
+ def test_subclass(self):
+ class F(float):
+ def __new__(cls, value):
+ return float.__new__(cls, value + 1)
+
+ f = F.fromhex((1.5).hex())
+ self.assertIs(type(f), F)
+ self.assertEqual(f, 2.5)
+
+ class F2(float):
+ def __init__(self, value):
+ self.foo = 'bar'
+
+ f = F2.fromhex((1.5).hex())
+ self.assertIs(type(f), F2)
+ self.assertEqual(f, 1.5)
+ self.assertEqual(getattr(f, 'foo', 'none'), 'bar')
+
if __name__ == '__main__':
unittest.main()