Skip to content

Commit ae2b62e

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 008e4c6 commit ae2b62e

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
@@ -2441,10 +2441,6 @@ def __str__(self):
24412441
self.assertTypedEqual(StrSubclass(StrWithStr(OtherStrSubclass('abc'))),
24422442
StrSubclass('abc'))
24432443

2444-
str_value = StrSubclass('abc')
2445-
self.assertIs(str(WithStr(str_value)), str_value)
2446-
self.assertIs(str(StrWithStr(str_value)), str_value)
2447-
24482444
self.assertTypedEqual(str(WithRepr('<abc>')), '<abc>')
24492445
self.assertTypedEqual(str(WithRepr(StrSubclass('<abc>'))), StrSubclass('<abc>'))
24502446
self.assertTypedEqual(StrSubclass(WithRepr('<abc>')), StrSubclass('<abc>'))
@@ -2453,9 +2449,6 @@ def __str__(self):
24532449
self.assertTypedEqual(StrSubclass(WithRepr(OtherStrSubclass('<abc>'))),
24542450
StrSubclass('<abc>'))
24552451

2456-
repr_value = StrSubclass('<abc>')
2457-
self.assertIs(str(WithRepr(repr_value)), repr_value)
2458-
24592452
def test_unicode_repr(self):
24602453
class s1:
24612454
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)