[pypy-commit] pypy default: Add a test. The fix is just killing 3 lines, including a comment that

arigo noreply at buildbot.pypy.org
Wed Sep 5 09:14:59 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r57140:89ae68436535
Date: 2012-09-05 09:14 +0200
http://bitbucket.org/pypy/pypy/changeset/89ae68436535/

Log:	Add a test. The fix is just killing 3 lines, including a comment
	that is not longer true.

diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py
--- a/pypy/module/_sre/interp_sre.py
+++ b/pypy/module/_sre/interp_sre.py
@@ -275,9 +275,6 @@
         if last_pos < ctx.end:
             sublist_w.append(slice_w(space, ctx, last_pos, ctx.end,
                                      space.w_None))
-        if n == 0:
-            # not just an optimization -- see test_sub_unicode
-            return w_string, n
 
         if space.is_true(space.isinstance(w_string, space.w_unicode)):
             w_emptystr = space.wrap(u'')
diff --git a/pypy/module/_sre/test/test_app_sre.py b/pypy/module/_sre/test/test_app_sre.py
--- a/pypy/module/_sre/test/test_app_sre.py
+++ b/pypy/module/_sre/test/test_app_sre.py
@@ -220,6 +220,24 @@
             return ''
         assert (u"bb\u3039b", 2) == re.subn("[aA]", call_me, "babAb")
 
+    def test_sub_subclass_of_str(self):
+        import re
+        class MyString(str):
+            pass
+        class MyUnicode(unicode):
+            pass
+        s1 = MyString('zz')
+        s2 = re.sub('aa', 'bb', s1)
+        assert s2 == s1
+        assert type(s2) is str       # and not MyString
+        s2 = re.sub(u'aa', u'bb', s1)
+        assert s2 == s1
+        assert type(s2) is str       # and not MyString
+        u1 = MyUnicode(u'zz')
+        u2 = re.sub(u'aa', u'bb', u1)
+        assert u2 == u1
+        assert type(u2) is unicode   # and not MyUnicode
+
     def test_match_array(self):
         import re, array
         a = array.array('c', 'hello')


More information about the pypy-commit mailing list