diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-12 07:37:58 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-12 07:37:58 (GMT) |
commit | ea36c941a1b2ad6582a35bc42aa70da9600d2841 (patch) | |
tree | e915477a42189e490044a15d786a18382064bc1f /Lib/test/test_float.py | |
parent | 9de7efe5ab40c19775dcc9ca88adf58d906fc53d (diff) | |
download | cpython-ea36c941a1b2ad6582a35bc42aa70da9600d2841.zip cpython-ea36c941a1b2ad6582a35bc42aa70da9600d2841.tar.gz cpython-ea36c941a1b2ad6582a35bc42aa70da9600d2841.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.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 48f7a70..cb1f6db 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -1355,6 +1355,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() |