Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.

This commit is contained in:
Serhiy Storchaka 2016-05-12 10:39:32 +03:00
commit 1f364438ad
6 changed files with 56 additions and 21 deletions

View file

@ -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()