Commits

Victor Stinner committed 9c1b769

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

Comments (0)

Files changed (2)

Lib/test/test_unicode.py

         self.checkequalnofix('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1)
         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):
         with support.check_warnings():
             warnings.simplefilter('ignore', BytesWarning)

Objects/unicodeobject.c

     else if (maxcount == 0 || slen == 0)
         goto nothing;
 
+    if (str1 == str2)
+        goto nothing;
     if (skind < kind1)
         /* substring too wide to be present */
         goto nothing;