Index: Python/ceval.c =================================================================== --- Python/ceval.c (revision 69514) +++ Python/ceval.c (working copy) @@ -4119,6 +4119,21 @@ t = PySequence_Tuple(stararg); if (t == NULL) { if (PyErr_ExceptionMatches(PyExc_TypeError)) { + /* There is possibly a more clarifying + * exception already set. Checking.. */ + PyTypeObject *star_t = Py_TYPE(stararg); + getiterfunc star_it = NULL; + if (PyType_HasFeature(star_t, + Py_TPFLAGS_HAVE_ITER) && + !PyInstance_Check(stararg)) { + star_it = star_t->tp_iter; + } + if (star_it != NULL || + PySequence_Check(stararg)) { + /* Do not override the current + * exception. */ + goto ext_call_fail; + } PyErr_Format(PyExc_TypeError, "%.200s%.200s argument after * " "must be a sequence, not %200s", Index: Lib/test/test_extcall.py =================================================================== --- Lib/test/test_extcall.py (revision 69514) +++ Lib/test/test_extcall.py (working copy) @@ -127,6 +127,17 @@ >>> g(*Nothing()) 0 (1, 2, 3) {} +Checking that the traceback is not being replaced when there is a better +one available + + >>> def g2(): + ... yield iter(None) + ... + >>> list(*g2()) + Traceback (most recent call last): + ... + TypeError: 'NoneType' object is not iterable + Make sure that the function doesn't stomp the dictionary >>> d = {'a': 1, 'b': 2, 'c': 3}