diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-25 13:53:19 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-11-25 13:53:19 (GMT) |
commit | bb6e4a0b31402f2e242f8f4be9a26e07d3dcc1b7 (patch) | |
tree | 552f1bdf983de7b8957bb65597c691c932d063db /Lib/test/test_bytes.py | |
parent | dde0815c359fc321b0e7a94f885132e2e77534a1 (diff) | |
parent | f9afda57ad7d0394531982b2c9de8301c5a54e45 (diff) | |
download | cpython-bb6e4a0b31402f2e242f8f4be9a26e07d3dcc1b7.zip cpython-bb6e4a0b31402f2e242f8f4be9a26e07d3dcc1b7.tar.gz cpython-bb6e4a0b31402f2e242f8f4be9a26e07d3dcc1b7.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_bytes.py')
-rw-r--r-- | Lib/test/test_bytes.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 87799df..cc951cf 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -793,6 +793,14 @@ class BytesTest(BaseBytesTest, unittest.TestCase): def __index__(self): return 42 self.assertEqual(bytes(A()), b'a') + # Issue #24731 + class A: + def __bytes__(self): + return OtherBytesSubclass(b'abc') + self.assertEqual(bytes(A()), b'abc') + self.assertIs(type(bytes(A())), OtherBytesSubclass) + self.assertEqual(BytesSubclass(A()), b'abc') + self.assertIs(type(BytesSubclass(A())), BytesSubclass) # Test PyBytes_FromFormat() def test_from_format(self): @@ -1647,6 +1655,9 @@ class ByteArraySubclass(bytearray): class BytesSubclass(bytes): pass +class OtherBytesSubclass(bytes): + pass + class ByteArraySubclassTest(SubclassTest, unittest.TestCase): type2test = bytearray subclass2test = ByteArraySubclass |