Issue 20959: print gives wrong error when printing *generator (original) (raw)

One of the more interesting ways to use print is printing output of a generator, as print(*generator()). But if the generator generates a typeError, you get a very unhelpful error message:

#the way it works OK def f(): yield 'a'+'b' ... print(*f()) ab #Now with a type error def f(): yield 'a'+5 ... print(*f()) Traceback (most recent call last): File "", line 1, in TypeError: print() argument after * must be a sequence, not generator

The problem is twofold: