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

Returning an exception object from a coroutine triggers implicit exception chaining?!? #73786

Closed
njsmith opened this issue Feb 19, 2017 · 4 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@njsmith
Copy link
Contributor

njsmith commented Feb 19, 2017

BPO 29600
Nosy @njsmith, @serhiy-storchaka, @1st1
PRs
  • bpo-29600: Fix wrapping into StopIteration of return values in generators #644
  • 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 2017-03-12.21:04:58.138>
    created_at = <Date 2017-02-19.13:44:49.407>
    labels = ['interpreter-core', 'type-bug', '3.7']
    title = 'Returning an exception object from a coroutine triggers implicit exception chaining?!?'
    updated_at = <Date 2017-03-14.13:38:14.161>
    user = 'https://github.com/njsmith'

    bugs.python.org fields:

    activity = <Date 2017-03-14.13:38:14.161>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-03-12.21:04:58.138>
    closer = 'yselivanov'
    components = ['Interpreter Core']
    creation = <Date 2017-02-19.13:44:49.407>
    creator = 'njs'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 29600
    keywords = []
    message_count = 4.0
    messages = ['288133', '289503', '289577', '289583']
    nosy_count = 3.0
    nosy_names = ['njs', 'serhiy.storchaka', 'yselivanov']
    pr_nums = ['644']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29600'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @njsmith
    Copy link
    Contributor Author

    njsmith commented Feb 19, 2017

    The following code prints "KeyError()", which is obviously wrong and rather baffling. Just passing an exception object around *as an object* should not trigger implicit exception chaining!

    If you replace the async functions with regular functions then it prints "None", as expected.

    Checked on 3.5, 3.6, and more-or-less current master -- bug is present in all 3.

    ------------

    async def f():
        return ValueError()
    
    async def g():
        try:
            raise KeyError
        except:
            value_error = await f()
            print(repr(value_error.__context__))

    try:
    g().send(None)
    except StopIteration:
    pass

    @njsmith njsmith added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Feb 19, 2017
    @1st1
    Copy link
    Member

    1st1 commented Mar 12, 2017

    What a bizarre bug. Created a PR with a fix.

    Nathaniel, please put me in a nosy list when you submit issues about generators/coroutines.

    @1st1 1st1 closed this as completed Mar 12, 2017
    @1st1 1st1 added the type-bug An unexpected behavior, bug, or error label Mar 12, 2017
    @serhiy-storchaka
    Copy link
    Member

    I am wondering how much of other uses of PyErr_SetObject() are affected by similar bugs?

    @1st1
    Copy link
    Member

    1st1 commented Mar 14, 2017

    I am wondering how much of other uses of PyErr_SetObject() are affected by similar bugs?

    Only when we use an exception to carry a return value. AFAIK StopIteration is the only such case.

    @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
    3.7 (EOL) end of life 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

    3 participants