diff -r 5973743a52a1 Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst Sun Mar 06 18:10:58 2011 -0600 +++ b/Doc/reference/expressions.rst Mon Mar 07 08:16:01 2011 +0100 @@ -668,11 +668,11 @@ there were no excess keyword arguments. If the syntax ``*expression`` appears in the function call, ``expression`` must -evaluate to a sequence. Elements from this sequence are treated as if they were -additional positional arguments; if there are positional arguments *x1*,..., -*xN*, and ``expression`` evaluates to a sequence *y1*, ..., *yM*, this is -equivalent to a call with M+N positional arguments *x1*, ..., *xN*, *y1*, ..., -*yM*. +evaluate to an iterable. Elements from this iterable are treated as if they +were additional positional arguments; if there are positional arguments +*x1*,..., *xN*, and ``expression`` evaluates to a sequence *y1*, ..., *yM*, +this is equivalent to a call with M+N positional arguments *x1*, ..., *xN*, +*y1*, ..., *yM*. A consequence of this is that although the ``*expression`` syntax may appear *after* some keyword arguments, it is processed *before* the keyword arguments diff -r 5973743a52a1 Lib/test/test_extcall.py --- a/Lib/test/test_extcall.py Sun Mar 06 18:10:58 2011 -0600 +++ b/Lib/test/test_extcall.py Mon Mar 07 08:16:01 2011 +0100 @@ -92,7 +92,7 @@ >>> g(*Nothing()) Traceback (most recent call last): ... - TypeError: g() argument after * must be a sequence, not Nothing + TypeError: g() argument after * must be an iterable, not Nothing >>> class Nothing: ... def __len__(self): return 5 @@ -101,7 +101,7 @@ >>> g(*Nothing()) Traceback (most recent call last): ... - TypeError: g() argument after * must be a sequence, not Nothing + TypeError: g() argument after * must be an iterable, not Nothing >>> class Nothing(): ... def __len__(self): return 5 @@ -127,6 +127,45 @@ >>> g(*Nothing()) 0 (1, 2, 3) {} +Check for issue #4806: Does a TypeError in a generator get propagated with the +right error message? (Also check with other iterables.) + + >>> def broken(): raise TypeError("myerror") + ... + + >>> g(*(broken() for i in range(1))) + Traceback (most recent call last): + ... + TypeError: myerror + + >>> class BrokenIterable1: + ... def __iter__(self): + ... raise TypeError('myerror') + ... + >>> g(*BrokenIterable1()) + Traceback (most recent call last): + ... + TypeError: myerror + + >>> class BrokenIterable2: + ... def __iter__(self): + ... yield 0 + ... raise TypeError('myerror') + ... + >>> g(*BrokenIterable2()) + Traceback (most recent call last): + ... + TypeError: myerror + + >>> class BrokenSequence: + ... def __getitem__(self, idx): + ... raise TypeError('myerror') + ... + >>> f(*BrokenSequence()) + Traceback (most recent call last): + ... + TypeError: myerror + Make sure that the function doesn't stomp the dictionary >>> d = {'a': 1, 'b': 2, 'c': 3} @@ -166,17 +205,17 @@ >>> h(*h) Traceback (most recent call last): ... - TypeError: h() argument after * must be a sequence, not function + TypeError: h() argument after * must be an iterable, not function >>> dir(*h) Traceback (most recent call last): ... - TypeError: dir() argument after * must be a sequence, not function + TypeError: dir() argument after * must be an iterable, not function >>> None(*h) Traceback (most recent call last): ... - TypeError: NoneType object argument after * must be a sequence, \ + TypeError: NoneType object argument after * must be an iterable, \ not function >>> h(**h) diff -r 5973743a52a1 Python/ceval.c --- a/Python/ceval.c Sun Mar 06 18:10:58 2011 -0600 +++ b/Python/ceval.c Mon Mar 07 08:16:01 2011 +0100 @@ -4127,10 +4127,12 @@ PyObject *t = NULL; t = PySequence_Tuple(stararg); if (t == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { + if (PyErr_ExceptionMatches(PyExc_TypeError) && + (Py_TYPE(stararg)->tp_iter == NULL) && + !PySequence_Check(stararg)) { PyErr_Format(PyExc_TypeError, "%.200s%.200s argument after * " - "must be a sequence, not %200s", + "must be an iterable, not %200s", PyEval_GetFuncName(func), PyEval_GetFuncDesc(func), stararg->ob_type->tp_name);