[pypy-svn] r59008 - in pypy/trunk/pypy/module/_sre: . test

arigo at codespeak.net arigo at codespeak.net
Sat Oct 11 19:56:19 CEST 2008


Author: arigo
Date: Sat Oct 11 19:56:18 2008
New Revision: 59008

Modified:
   pypy/trunk/pypy/module/_sre/app_sre.py
   pypy/trunk/pypy/module/_sre/test/test_app_sre.py
Log:
Test and fix for a strange type rule of CPython.


Modified: pypy/trunk/pypy/module/_sre/app_sre.py
==============================================================================
--- pypy/trunk/pypy/module/_sre/app_sre.py	(original)
+++ pypy/trunk/pypy/module/_sre/app_sre.py	Sat Oct 11 19:56:18 2008
@@ -106,6 +106,9 @@
             else:
                 state.start = state.string_position
 
+        if n == 0:       # not just an optimization -- see test_sub_unicode
+            return string, n
+
         if last_pos < state.end:
             sublist.append(string[last_pos:state.end])
         if need_unicode:

Modified: pypy/trunk/pypy/module/_sre/test/test_app_sre.py
==============================================================================
--- pypy/trunk/pypy/module/_sre/test/test_app_sre.py	(original)
+++ pypy/trunk/pypy/module/_sre/test/test_app_sre.py	Sat Oct 11 19:56:18 2008
@@ -182,6 +182,11 @@
     def test_sub_unicode(self):
         import re
         assert isinstance(re.sub(u"a", u"b", u""), unicode)
+        # the input is returned unmodified if no substitution is performed,
+        # which (if interpreted literally, as CPython does) gives the
+        # following strangeish rules:
+        assert isinstance(re.sub(u"a", u"b", "diwoiioamoi"), unicode)
+        assert isinstance(re.sub(u"a", u"b", "diwoiiobmoi"), str)
 
     def test_sub_callable(self):
         import re



More information about the Pypy-commit mailing list