diff options
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 53a80f4..8158f78 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -779,6 +779,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): @@ -1552,6 +1560,9 @@ class ByteArraySubclass(bytearray): class BytesSubclass(bytes): pass +class OtherBytesSubclass(bytes): + pass + class ByteArraySubclassTest(SubclassTest, unittest.TestCase): type2test = bytearray subclass2test = ByteArraySubclass |