Index: Python/ceval.c =================================================================== --- Python/ceval.c (Revision 83743) +++ Python/ceval.c (Arbeitskopie) @@ -4139,10 +4139,11 @@ PyObject *t = NULL; t = PySequence_Tuple(stararg); if (t == NULL) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { + if (PyErr_ExceptionMatches(PyExc_TypeError) && + !PyIter_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); Index: Doc/reference/expressions.rst =================================================================== --- Doc/reference/expressions.rst (Revision 83743) +++ Doc/reference/expressions.rst (Arbeitskopie) @@ -661,11 +661,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 Index: Lib/test/test_extcall.py =================================================================== --- Lib/test/test_extcall.py (Revision 83743) +++ Lib/test/test_extcall.py (Arbeitskopie) @@ -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,17 @@ >>> g(*Nothing()) 0 (1, 2, 3) {} +Check for issue #4806: Does a TypeError in a generator get propagated with the +right error message? + + >>> def broken(): raise TypeError("myerror") + ... + + >>> g(*(broken() for i in range(1))) + 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 +177,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)