summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-25 15:47:01 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-25 15:47:01 +0200
commit15095800a381a396cbc077cb5320203a8feae51a (patch)
treeba1f16c1b9be09a1f14d3af644c39e52924ee63f /Lib/test/test_bytes.py
parenta49de6be3669e4698ea55d22e0fdebb29be63f2e (diff)
downloadcpython-git-15095800a381a396cbc077cb5320203a8feae51a.tar.gz
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.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index b00573f4e4..0a73fcbb91 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -744,6 +744,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):
@@ -1465,6 +1473,9 @@ class ByteArraySubclass(bytearray):
class BytesSubclass(bytes):
pass
+class OtherBytesSubclass(bytes):
+ pass
+
class ByteArraySubclassTest(SubclassTest, unittest.TestCase):
type2test = bytearray
subclass2test = ByteArraySubclass