Skip to content

Instantly share code, notes, and snippets.

@njsmith
Last active November 8, 2025 14:25
Show Gist options
  • Select an option

  • Save njsmith/ac696325c7d59bb7c5f1c7bb29b090df to your computer and use it in GitHub Desktop.

Select an option

Save njsmith/ac696325c7d59bb7c5f1c7bb29b090df to your computer and use it in GitHub Desktop.
async def f():
return ValueError()
async def g():
try:
raise KeyError
except:
value_error = await f()
# This prints: KeyError() in CPython 3.5, 3.6, current master
# Apparently returning an exception object from an async function triggers
# implicit exception chaining?!
print(repr(value_error.__context__))
try:
g().send(None)
except StopIteration:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment