[New-bugs-announce] [issue29600] Returning an exception object from a coroutine triggers implicit exception chaining?!?

Nathaniel Smith report at bugs.python.org
Sun Feb 19 08:44:49 EST 2017


New submission from Nathaniel Smith:

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

----------
components: Interpreter Core
messages: 288133
nosy: njs
priority: normal
severity: normal
status: open
title: Returning an exception object from a coroutine triggers implicit exception chaining?!?
versions: Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29600>
_______________________________________


More information about the New-bugs-announce mailing list