Index: Lib/test/test_str2unicode.py =================================================================== --- Lib/test/test_str2unicode.py (revision 3131) +++ Lib/test/test_str2unicode.py (working copy) @@ -2,18 +2,26 @@ class TestStrReturnsUnicode(unittest.TestCase): def test_join(self): - self.assertEquals(unicode, type(''.join([u'blah']))) + self.assertEquals(unicode, type(''.join([u'blah']))) def test_replace(self): - self.assertEquals(unicode, type('hello'.replace('o', u'o'))) + self.assertEquals(unicode, type('hello'.replace('o', u'o'))) + def test_string_formatting(self): + self.assertEquals(unicode, type('%s' % u'x')) + self.assertEquals(unicode, type('%s %s' % (u'x', 'y'))) class TestStrReturnsStr(unittest.TestCase): def test_join(self): - self.assertEquals(str, type(''.join(['blah']))) + self.assertEquals(str, type(''.join(['blah']))) def test_replace(self): - self.assertEquals(str, type('hello'.replace('o', 'oo'))) + self.assertEquals(str, type('hello'.replace('o', 'oo'))) + def test_string_formatting(self): + self.assertEquals(str, type('%s' % 'x')) + self.assertEquals(str, type('%s %s' % ('x', 'y'))) + + if __name__ == '__main__': unittest.main() Index: src/org/python/core/PyString.java =================================================================== --- src/org/python/core/PyString.java (revision 3131) +++ src/org/python/core/PyString.java (working copy) @@ -2044,8 +2044,20 @@ } public PyObject str___mod__(PyObject other){ - StringFormatter fmt = new StringFormatter(string); - return createInstance(fmt.format(other)); + String result = new StringFormatter(string).format(other); + if (other instanceof PyUnicode) { + return new PyUnicode(result); + } + if (!(other instanceof PyString)) { + PyObject iter = other.__iter__(); + PyObject obj = null; + for (int i = 0; (obj = iter.__iternext__()) != null; i++) { + if (obj instanceof PyUnicode) { + return new PyUnicode(result); + } + } + } + return new PyString(result); } public PyObject __int__() {