mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #25766: Special method __bytes__() now works in str subclasses.
This commit is contained in:
commit
3182db356c
3 changed files with 20 additions and 6 deletions
|
@ -793,6 +793,12 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
|
|||
def __index__(self):
|
||||
return 42
|
||||
self.assertEqual(bytes(A()), b'a')
|
||||
# Issue #25766
|
||||
class A(str):
|
||||
def __bytes__(self):
|
||||
return b'abc'
|
||||
self.assertEqual(bytes(A('\u20ac')), b'abc')
|
||||
self.assertEqual(bytes(A('\u20ac'), 'iso8859-15'), b'\xa4')
|
||||
# Issue #24731
|
||||
class A:
|
||||
def __bytes__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue