Kaydet (Commit) 59de0ee9 authored tarafından Victor Stinner's avatar Victor Stinner

str.replace(a, a) is now returning str unchanged if a is a

üst 72ca65dc
...@@ -275,6 +275,12 @@ class UnicodeTest(string_tests.CommonTest, ...@@ -275,6 +275,12 @@ class UnicodeTest(string_tests.CommonTest,
self.checkequalnofix('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1) self.checkequalnofix('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1)
self.assertRaises(TypeError, 'replace'.replace, "r", 42) self.assertRaises(TypeError, 'replace'.replace, "r", 42)
@support.cpython_only
def test_replace_id(self):
a = 'a' # single ascii letters are singletons
text = 'abc'
self.assertIs(text.replace('a', 'a'), text)
def test_bytes_comparison(self): def test_bytes_comparison(self):
with support.check_warnings(): with support.check_warnings():
warnings.simplefilter('ignore', BytesWarning) warnings.simplefilter('ignore', BytesWarning)
......
...@@ -9604,6 +9604,8 @@ replace(PyObject *self, PyObject *str1, ...@@ -9604,6 +9604,8 @@ replace(PyObject *self, PyObject *str1,
else if (maxcount == 0 || slen == 0) else if (maxcount == 0 || slen == 0)
goto nothing; goto nothing;
if (str1 == str2)
goto nothing;
if (skind < kind1) if (skind < kind1)
/* substring too wide to be present */ /* substring too wide to be present */
goto nothing; goto nothing;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment