mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
a49de6be36
commit
15095800a3
8 changed files with 50 additions and 10 deletions
|
@ -42,6 +42,9 @@ def duplicate_string(text):
|
|||
"""
|
||||
return text.encode().decode()
|
||||
|
||||
class StrSubclass(str):
|
||||
pass
|
||||
|
||||
class UnicodeTest(string_tests.CommonTest,
|
||||
string_tests.MixinStrUnicodeUserStringTest,
|
||||
string_tests.MixinStrUnicodeTest,
|
||||
|
@ -1412,11 +1415,8 @@ class UnicodeTest(string_tests.CommonTest,
|
|||
'unicode remains unicode'
|
||||
)
|
||||
|
||||
class UnicodeSubclass(str):
|
||||
pass
|
||||
|
||||
for text in ('ascii', '\xe9', '\u20ac', '\U0010FFFF'):
|
||||
subclass = UnicodeSubclass(text)
|
||||
subclass = StrSubclass(text)
|
||||
self.assertEqual(str(subclass), text)
|
||||
self.assertEqual(len(subclass), len(text))
|
||||
if text == 'ascii':
|
||||
|
@ -2169,6 +2169,9 @@ class UnicodeTest(string_tests.CommonTest,
|
|||
s = str(StrSubclassToStrSubclass("foo"))
|
||||
self.assertEqual(s, "foofoo")
|
||||
self.assertIs(type(s), StrSubclassToStrSubclass)
|
||||
s = StrSubclass(StrSubclassToStrSubclass("foo"))
|
||||
self.assertEqual(s, "foofoo")
|
||||
self.assertIs(type(s), StrSubclass)
|
||||
|
||||
def test_unicode_repr(self):
|
||||
class s1:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue