Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator as *args: TypeError replaced #58112

Closed
tifv mannequin opened this issue Jan 29, 2012 · 2 comments
Closed

Generator as *args: TypeError replaced #58112

tifv mannequin opened this issue Jan 29, 2012 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@tifv
Copy link
Mannequin

tifv mannequin commented Jan 29, 2012

BPO 13904
Nosy @terryjreedy, @tifv
Superseder
  • bpo-4806: Function calls taking a generator as star argument can mask TypeErrors in the generator
  • Files
  • typeerror-replaced-in-stararg.diff: patch
  • typeerror-replaced-in-stararg-test.diff: test
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-04.02:12:56.120>
    created_at = <Date 2012-01-29.16:38:40.303>
    labels = ['interpreter-core', 'type-bug']
    title = 'Generator as *args: TypeError replaced'
    updated_at = <Date 2012-02-04.02:12:56.020>
    user = 'https://github.com/tifv'

    bugs.python.org fields:

    activity = <Date 2012-02-04.02:12:56.020>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-02-04.02:12:56.120>
    closer = 'terry.reedy'
    components = ['Interpreter Core']
    creation = <Date 2012-01-29.16:38:40.303>
    creator = 'july'
    dependencies = []
    files = ['24358', '24359']
    hgrepos = []
    issue_num = 13904
    keywords = ['patch']
    message_count = 2.0
    messages = ['152243', '152579']
    nosy_count = 2.0
    nosy_names = ['terry.reedy', 'july']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '4806'
    type = 'behavior'
    url = 'https://bugs.python.org/issue13904'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    @tifv
    Copy link
    Mannequin Author

    tifv mannequin commented Jan 29, 2012

    >>> 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).

    @tifv tifv mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 29, 2012
    @terryjreedy
    Copy link
    Member

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant