classification
Title: Generator as *args: TypeError replaced
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Function calls taking a generator as star argument can mask TypeErrors in the generator
View: 4806
Assigned To: Nosy List: july, terry.reedy
Priority: normal Keywords: patch

Created on 2012-01-29 16:38 by july, last changed 2012-02-04 02:12 by terry.reedy. This issue is now closed.

Files
File name Uploaded Description Edit
typeerror-replaced-in-stararg.diff july, 2012-01-29 16:38 patch
typeerror-replaced-in-stararg-test.diff july, 2012-01-29 16:39 test review
Messages (2)
msg152243 - (view) Author: July Tikhonov (july) * Date: 2012-01-29 16:38
>>> set().union(*(None[k] for k in range(5)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: union() argument after * must be a sequence, not generator

Clearly, exception in not relevant, since next line works:

>>> set().union(*([k] for k in range(5)))
{0, 1, 2, 3, 4}

Correct exception would be

>>> None[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable

Problem is in python function call mechanics.
set().union can be replaced by any callable;
Generator can be replaced by any TypeError-raising iterable. Exceptions other then TypeError are handled correctly.

Python/ceval.c:4322
ext_do_call() converts stararg to tuple.
If any TypeError is raised, it is replaced with
TypeError("%s argument after * must be a sequence, not %s")


Proposed solution:

Probably, we can avoid replacing TypeError. Exceptions in the above cases would become relevant, and

>>> int(*None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type object argument after * must be a sequence, not NoneType

would become

>>> int(*None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable

so exception is still recognizable (and, may be, even more relevant, since we don't actually need _sequence_ as stararg, _iterable_ would be enough).
msg152579 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-02-04 02:12
I unlinked to see if I could link it to 4806 instead. Did not work. Please nosy yourself there and upload your files to *that* issue.
History
Date User Action Args
2012-02-04 02:12:56terry.reedysetstatus: open -> closed

superseder: Function calls taking a generator as star argument can mask TypeErrors in the generator
versions: + Python 2.7, Python 3.2
nosy: + terry.reedy

messages: + msg152579
resolution: duplicate
2012-02-04 02:10:01terry.reedysetfiles: + typeerror-replaced-in-stararg.diff
2012-02-04 02:08:31terry.reedysetfiles: - typeerror-replaced-in-stararg.diff
2012-01-29 16:39:09julysetfiles: + typeerror-replaced-in-stararg-test.diff
2012-01-29 16:38:40julycreate