Skip to content

Commit b2308bb

Browse files
author
Michael W. Hudson
committed
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.
1 parent aee2e28 commit b2308bb

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Lib/test/string_tests.py

+9
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,15 @@ def test_join(self):
657657
self.checkraises(TypeError, ' ', 'join')
658658
self.checkraises(TypeError, ' ', 'join', 7)
659659
self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123L]))
660+
try:
661+
def f():
662+
yield 4 + ""
663+
self.fixtype(' ').join(f())
664+
except TypeError, e:
665+
if '+' not in str(e):
666+
self.fail('join() ate exception message')
667+
else:
668+
self.fail('exception not raised')
660669

661670
def test_formatting(self):
662671
self.checkequal('+hello+', '+%s+', '__mod__', 'hello')

Lib/test/test_string.py

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def test_join(self):
5151

5252
self.checkraises(TypeError, string_tests.BadSeq1(), 'join', ' ')
5353
self.checkequal('a b c', string_tests.BadSeq2(), 'join', ' ')
54+
try:
55+
def f():
56+
yield 4 + ""
57+
self.fixtype(' ').join(f())
58+
except TypeError, e:
59+
if '+' not in str(e):
60+
self.fail('join() ate exception message')
61+
else:
62+
self.fail('exception not raised')
63+
64+
5465

5566

5667
class ModuleTest(unittest.TestCase):

Objects/stringobject.c

-4
Original file line numberDiff line numberDiff line change
@@ -1620,10 +1620,6 @@ string_join(PyStringObject *self, PyObject *orig)
16201620

16211621
seq = PySequence_Fast(orig, "");
16221622
if (seq == NULL) {
1623-
if (PyErr_ExceptionMatches(PyExc_TypeError))
1624-
PyErr_Format(PyExc_TypeError,
1625-
"sequence expected, %.80s found",
1626-
orig->ob_type->tp_name);
16271623
return NULL;
16281624
}
16291625

Objects/unicodeobject.c

-4
Original file line numberDiff line numberDiff line change
@@ -4148,10 +4148,6 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
41484148

41494149
fseq = PySequence_Fast(seq, "");
41504150
if (fseq == NULL) {
4151-
if (PyErr_ExceptionMatches(PyExc_TypeError))
4152-
PyErr_Format(PyExc_TypeError,
4153-
"sequence expected, %.80s found",
4154-
seq->ob_type->tp_name);
41554151
return NULL;
41564152
}
41574153

0 commit comments

Comments
 (0)