New submission from July Tikhonov <[email protected]>:
>>> 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).
----------
components: Interpreter Core
files: typeerror-replaced-in-stararg.diff
keywords: patch
messages: 152243
nosy: july
priority: normal
severity: normal
status: open
title: Generator as *args: TypeError replaced
type: behavior
versions: Python 3.3
Added file: http://bugs.python.org/file24358/typeerror-replaced-in-stararg.diff
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue13904>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com