mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.
This commit is contained in:
commit
1f364438ad
6 changed files with 56 additions and 21 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue