diff options
author | Michael W. Hudson <mwh@python.net> | 2005-10-21 11:45:01 (GMT) |
---|---|---|
committer | Michael W. Hudson <mwh@python.net> | 2005-10-21 11:45:01 (GMT) |
commit | b2308bb9be492937764a99007f5fd49b75fbefee (patch) | |
tree | e62df0ddeff790c58c067130b61e9f9d43840783 | |
parent | aee2e2829db8e8d4ea9f5b0bc900564cdebe9414 (diff) | |
download | cpython-b2308bb9be492937764a99007f5fd49b75fbefee.zip cpython-b2308bb9be492937764a99007f5fd49b75fbefee.tar.gz cpython-b2308bb9be492937764a99007f5fd49b75fbefee.tar.bz2 |
Fix bug:
[ 1327110 ] wrong TypeError traceback in generator expressions
by removing the code that can stomp on the users' TypeError raised by the
iterable argument to ''.join() -- PySequence_Fast (now?) gives a perfectly
reasonable message itself. Also, a couple of tests.
-rw-r--r-- | Lib/test/string_tests.py | 9 | ||||
-rw-r--r-- | Lib/test/test_string.py | 11 | ||||
-rw-r--r-- | Objects/stringobject.c | 4 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 4 |
4 files changed, 20 insertions, 8 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 9f092b9..60f5fdb 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -657,6 +657,15 @@ class MixinStrUnicodeUserStringTest: self.checkraises(TypeError, ' ', 'join') self.checkraises(TypeError, ' ', 'join', 7) self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123L])) + try: + def f(): + yield 4 + "" + self.fixtype(' ').join(f()) + except TypeError, e: + if '+' not in str(e): + self.fail('join() ate exception message') + else: + self.fail('exception not raised') def test_formatting(self): self.checkequal('+hello+', '+%s+', '__mod__', 'hello') diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index d80c3b6..fdd431d 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -51,6 +51,17 @@ class StringTest( self.checkraises(TypeError, string_tests.BadSeq1(), 'join', ' ') self.checkequal('a b c', string_tests.BadSeq2(), 'join', ' ') + try: + def f(): + yield 4 + "" + self.fixtype(' ').join(f()) + except TypeError, e: + if '+' not in str(e): + self.fail('join() ate exception message') + else: + self.fail('exception not raised') + + class ModuleTest(unittest.TestCase): diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 78560de..037fa6a 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1620,10 +1620,6 @@ string_join(PyStringObject *self, PyObject *orig) seq = PySequence_Fast(orig, ""); if (seq == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - PyErr_Format(PyExc_TypeError, - "sequence expected, %.80s found", - orig->ob_type->tp_name); return NULL; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 10ac80c..db2a690 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4148,10 +4148,6 @@ PyUnicode_Join(PyObject *separator, PyObject *seq) fseq = PySequence_Fast(seq, ""); if (fseq == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) - PyErr_Format(PyExc_TypeError, - "sequence expected, %.80s found", - seq->ob_type->tp_name); return NULL; } |