Disallow u"..." + b"..." and b"..." + u"...".

This commit is contained in:
Guido van Rossum 2007-04-13 02:23:57 +00:00
parent ad7d8d10b7
commit 84d79ddce2
2 changed files with 4 additions and 1 deletions

View file

@ -374,7 +374,7 @@ class BytesTest(unittest.TestCase):
self.assertEqual(b1 + "def", bytes("abcdef")) self.assertEqual(b1 + "def", bytes("abcdef"))
self.assertEqual("def" + b1, bytes("defabc")) self.assertEqual("def" + b1, bytes("defabc"))
self.assertRaises(TypeError, lambda: b1 + u"def") self.assertRaises(TypeError, lambda: b1 + u"def")
##self.assertRaises(TypeError, lambda: u"abc" + b2) # XXX FIXME self.assertRaises(TypeError, lambda: u"abc" + b2)
def test_repeat(self): def test_repeat(self):
b = bytes("abc") b = bytes("abc")

View file

@ -5535,6 +5535,9 @@ PyObject *PyUnicode_Concat(PyObject *left,
{ {
PyUnicodeObject *u = NULL, *v = NULL, *w; PyUnicodeObject *u = NULL, *v = NULL, *w;
if (PyBytes_Check(left) || PyBytes_Check(right))
return PyBytes_Concat(left, right);
/* Coerce the two arguments */ /* Coerce the two arguments */
u = (PyUnicodeObject *)PyUnicode_FromObject(left); u = (PyUnicodeObject *)PyUnicode_FromObject(left);
if (u == NULL) if (u == NULL)