Skip to content

Commit 9a11d44

Browse files
Copilotyouknowone
andcommitted
Align test_str with CPython and move local coverage
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
1 parent 5140534 commit 9a11d44

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

Lib/test/test_str.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,10 +2440,6 @@ def __str__(self):
24402440
self.assertTypedEqual(StrSubclass(StrWithStr(OtherStrSubclass('abc'))),
24412441
StrSubclass('abc'))
24422442

2443-
str_value = StrSubclass('abc')
2444-
self.assertIs(str(WithStr(str_value)), str_value)
2445-
self.assertIs(str(StrWithStr(str_value)), str_value)
2446-
24472443
self.assertTypedEqual(str(WithRepr('<abc>')), '<abc>')
24482444
self.assertTypedEqual(str(WithRepr(StrSubclass('<abc>'))), StrSubclass('<abc>'))
24492445
self.assertTypedEqual(StrSubclass(WithRepr('<abc>')), StrSubclass('<abc>'))
@@ -2452,9 +2448,6 @@ def __str__(self):
24522448
self.assertTypedEqual(StrSubclass(WithRepr(OtherStrSubclass('<abc>'))),
24532449
StrSubclass('<abc>'))
24542450

2455-
repr_value = StrSubclass('<abc>')
2456-
self.assertIs(str(WithRepr(repr_value)), repr_value)
2457-
24582451
def test_unicode_repr(self):
24592452
class s1:
24602453
def __repr__(self):

extra_tests/snippets/builtin_str_subclass.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ def __init__(self, value):
1919
assert y + " other" == "1 other"
2020
assert y.x == "substr"
2121

22+
23+
class ReprStrSubclass(str):
24+
pass
25+
26+
27+
class WithStr:
28+
def __init__(self, value):
29+
self.value = value
30+
31+
def __str__(self):
32+
return self.value
33+
34+
35+
class WithRepr:
36+
def __init__(self, value):
37+
self.value = value
38+
39+
def __repr__(self):
40+
return self.value
41+
42+
43+
str_value = ReprStrSubclass("abc")
44+
assert str(WithStr(str_value)) is str_value
45+
46+
repr_value = ReprStrSubclass("<abc>")
47+
assert str(WithRepr(repr_value)) is repr_value
48+
2249
## Base strings currently get an attribute dict, but shouldn't.
2350
# with assert_raises(AttributeError):
2451
# "hello".x = 5

0 commit comments

Comments
 (0)