There's one issue with your stack_context handling.
It's good that you stack_context.wrap() the callback when setting it in _Waiter.
You'll have to call that callback inside a NullContext() to prevent a stack_context leak in set().
Take this scenario for example.
set()'s ExceptionStackContext will catch the exception in raise_callback().
---
def set_result():
with stack_context.ExceptionStackContext(catch_set_result_exception):
result.set('hello')
def callback(value):
outcomes['value'] = value
loop.add_callback(raise_callback)
def raise_callback():
assert False
def catch_set_result_exception(type, value, traceback):
outcomes['set_result_exc'] = type
return True
result.get(callback)
loop.add_timeout(time.time() + .01, set_result)
loop.start()
self.assertEqual(outcomes['value'], 'hello')
self.assertNotEqual(outcomes['set_result_exc'], AssertionError)