diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 0479601fc23517b130f5fbe47f52152bdec4e914..78181121228f0820c865c3315a62375a293dcb88 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -65,14 +65,12 @@ class CommonTest(unittest.TestCase): self.assertTrue(object is not realresult) # check that object.method(*args) raises exc - def checkraises(self, exc, object, methodname, *args): - object = self.fixtype(object) + def checkraises(self, exc, obj, methodname, *args): + obj = self.fixtype(obj) args = self.fixtype(args) - self.assertRaises( - exc, - getattr(object, methodname), - *args - ) + with self.assertRaises(exc) as cm: + getattr(obj, methodname)(*args) + self.assertNotEqual(cm.exception.message, '') # call object.method(*args) without any checks def checkcall(self, object, methodname, *args): @@ -1057,6 +1055,7 @@ class MixinStrUnicodeUserStringTest: self.checkequal('a b c', ' ', 'join', BadSeq2()) self.checkraises(TypeError, ' ', 'join') + self.checkraises(TypeError, ' ', 'join', None) self.checkraises(TypeError, ' ', 'join', 7) self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123L])) try: diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index 0d07b913942f2a88ad9246c96cb127f76c7171e7..f69255bb3320f79d1ac889ab82b115e95b198678 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -16,13 +16,10 @@ class StringTest( realresult ) - def checkraises(self, exc, object, methodname, *args): - self.assertRaises( - exc, - getattr(string, methodname), - object, - *args - ) + def checkraises(self, exc, obj, methodname, *args): + with self.assertRaises(exc) as cm: + getattr(string, methodname)(obj, *args) + self.assertNotEqual(cm.exception.message, '') def checkcall(self, object, methodname, *args): getattr(string, methodname)(object, *args) diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py index 51d8e8b7e1cf77efcd2be834199b278e5990517f..9cca14acfda8f1146f5a7f6731d2f289f0d7c5ab 100644 --- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -28,14 +28,12 @@ class UserStringTest( realresult ) - def checkraises(self, exc, object, methodname, *args): - object = self.fixtype(object) + def checkraises(self, exc, obj, methodname, *args): + obj = self.fixtype(obj) # we don't fix the arguments, because UserString can't cope with it - self.assertRaises( - exc, - getattr(object, methodname), - *args - ) + with self.assertRaises(exc) as cm: + getattr(obj, methodname)(*args) + self.assertNotEqual(cm.exception.message, '') def checkcall(self, object, methodname, *args): object = self.fixtype(object) diff --git a/Misc/ACKS b/Misc/ACKS index 3fb951cddc90ec65a1086bd5acc9243544cae53c..fad0d8856be072619b32901d602a5bde4a531e60 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1007,6 +1007,7 @@ Mike Pall Todd R. Palmer Juan David Ibáñez Palomar Jan Palus +Yongzhi Pan Mathias Panzenböck M. Papillon Peter Parente diff --git a/Misc/NEWS b/Misc/NEWS index da2c5544db442d492a17a9e19e2ec78f9d5651dc..237da4169a0711213175bd47c68cd314151a529d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 2.7.9? Core and Builtins ----------------- +- Issue #22379: Fix empty exception message in a TypeError raised in + ``str.join``. + - Issue #22221: Now the source encoding declaration on the second line isn't effective if the first line contains anything except a comment. diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 0b6d36cee0b84ae4b7d22d5b3ed7a5b0af36a11a..f95857ab83eab13023f8f934a0eaae869f4eac4b 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1594,7 +1594,7 @@ string_join(PyStringObject *self, PyObject *orig) Py_ssize_t i; PyObject *seq, *item; - seq = PySequence_Fast(orig, ""); + seq = PySequence_Fast(orig, "can only join an iterable"); if (seq == NULL) { return NULL; }